pimpl idiom



flyfish 2014-9-30




pimpl是Pointer to implementation的缩写

为什么要使用pimpl

1最小化编译依赖

2接口与实现分离

3可移植



pimpl idiom也被称作Cheshire Cat , Compiler Firewall idiom.,d-pointer

这个技术在设计模式中作为桥接模式(Bridge pattern.)来描写叙述

看MSDN的演示样例



Pimpl header

// my_class.h
class my_class {
// ... all public and protected stuff goes here ...
private:
class impl; unique_ptr<impl> pimpl; // opaque type here
};

Pimpl implementation

// my_class.cpp
class my_class::impl { // defined privately here
// ... all private data and functions: all of these
// can now change without recompiling callers ...
};
my_class::my_class(): pimpl( new impl )
{
// ... set impl values ...
}

实现部分被隐藏在class my_class::impl{......} 中



简单描写叙述就是将一个类切割为两个类,一个提供接口。一个负责实现。

既能最小化编译依赖,又能接口与实现分离。

pimpl idiom的更多相关文章

  1. Pimpl Idiom /handle body idiom

    在读<Effective C++>和项目源代码时,看到pImpl Idiom.它可以用来降低文件间的编译依赖关系,通过把一个Class分成两个Class,一个只提供接口,另一个负责实现该接 ...

  2. pimpl idiom vs. bridge design pattern

    http://stackoverflow.com/questions/2346163/pimpl-idiom-vs-bridge-design-pattern

  3. PIMPL(二)

    文档下载 上一篇文档,PIMPL(一) 1 如何使用PIMPL 有多种方式实现PIMPL,这里按照<Effective C++>中介绍的方式. 1.1 基本步骤 假设原有Person如下: ...

  4. PIMPL(一)

    1 参考 <effective C++> 条款31:将文件间的编译关系降至最低 PIMPL Idiom: http://c2.com/cgi/wiki?PimplIdiom 2 什么是PI ...

  5. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  6. Effective Modern C++ 42 Specific Ways to Improve Your Use of C++11 and C++14

    Item 1: Understand template type deduction. Item 2: Understand auto type deduction. Item 3: Understa ...

  7. PCurve - Curve on Surface

    PCurve - Curve on Surface eryar@163.com Abstract. 本文通过给出曲面上曲线PCurve的定义来对OpenCascade中的Curve On Surfac ...

  8. callback的实现

    Callback.h 继承层次 CallBack实现类 基类 第一层子类 第二层子类 第三层子类 SimpleRefCount CallbackImplBase CallbackImpl Functo ...

  9. C++11 现代C++风格的新元素--简介

    C++11标准推出了很多有用的新特性,本文特别关注那些相比C++98更像是一门新语言的特性,理由是: 这些特性改变了编写C++程序使用的代码风格和习语[译注 1],通常也包括你设计C++函数库的方式. ...

随机推荐

  1. 【Qt】仿QQ表情选择控件

         表情选择控件在聊天应用中常常要用到,做起来尽管不复杂可是非常繁琐.特别是有些图标须要按顺序排列.每次重做必定是非常费时.所以我将聊天表情选择控件封装成一个独立的类QFaceSelectWid ...

  2. 【Python】Python 微服务框架 nameko

    nameko: 1.支持服务发现.负载均衡 2.支持依赖自动注入,使用很方便 3.缺点:超时.限速.权限等机制不完善 代码示例:https://github.com/junneyang/nameko- ...

  3. DIRECT Project

    http://www.healthit.gov/policy-researchers-implementers/direct-project Launched in March 2010 as a p ...

  4. [NPM] Use npx to run commands with different Node.js versions

    We will use npx to run a package using different versions of Node.js. This can become valuable when ...

  5. Python访问PostGIS(建表、空间索引、分区表)

    #encoding: utf-8 __author__ = 'Administrator' import psycopg2 import ppygis import datetime import s ...

  6. Android实现Material Design风格的设置页面(滑动开关控件)

    前言 本文链接 http://blog.csdn.net/never_cxb/article/details/50763271 转载请注明出处 參考了这篇文章 Material Design 风格的设 ...

  7. 翻译记忆软件-塔多思TRADO经典教程_5

    TRADOS新手必读 共有篇贴子 TRADOS新手必读   译海撷英系列之软件漫谈之TRADOS新手必读 作者:苏任 我很喜欢到翻译中国网站上来四处看看,一开始主要是关心应用资料和软件,后来就对网友的 ...

  8. Java从零开始学十三(封装)

    一.什么是封装,为什么要封装 对面向对象而言:封装就是将方法和属性包装到一个程序单元中,并且这个单元以类的形式实现. 简单讲:封闭就是将属性私有化,提供公有方法来访问私有属性 封装的作用: 封装反映和 ...

  9. ThinkPHP的A方法,R方法,M方法,D方法区别

    在Thinkphp中,实例化对象有这么几种方法,如果是类,有A和R方法,区别是A方法只是对象的实例化,而R方法是可以同时实例化对象里面的方法的,这里需要去指定,如下面的实例代码: <?php n ...

  10. MySQL 联合索引测试

    搭建测试环境 1:创建表 CREATE TABLE tab_index (id int(5), age int(3), dte datetime); 2:插入测试数据 INSERT INTO tab_ ...