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. Decorator Wrapper 装饰模式 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  2. 你应该了解的CSS语义化命名方式及常用命名规则

    CSS语义化命名 从上图我们可以大概看出这里有两种CSS的命名方式:1.结构化命名法:2.语义化命名法. 结构化命名法:根据页面中板块的位置而命名,如上图中的content-left,这时如果我们想把 ...

  3. Dijkstra(迪杰斯特拉)算法求解最短路径

    过程 首先需要记录每个点到原点的距离,这个距离会在每一轮遍历的过程中刷新.每一个节点到原点的最短路径是其上一个节点(前驱节点)到原点的最短路径加上前驱节点到该节点的距离.以这个原则,经过N轮计算就能得 ...

  4. linux系统下调度数据库类型资源库中的kettle job

    已经存在kettle的一个资源库enfo,在目录/works/wxj下面有一个job (testmailsuccess.kjb)如何实现手工在kettle外部执行此job和让系统每天定时的调用此job ...

  5. 用vs2013开发node.js的addon.

        下载node.js的源代码. https://github.com/joyent/node 如果用svn下载,后面加上/trunk,以免把用不着的branches也下载下来,浪费时间. 安装V ...

  6. [Functional Programming] Build a Linear congruential generator

    What we are going to do in this post, is to build a random number generator. As you might know that ...

  7. C#.NET常见问题(FAQ)-如何清空stringbuilder

    就红色的代码可以: System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("hello" ...

  8. Java操作Excel文件以及在Android中的应用

    本文章由临江仙原创,转载请注明出处:http://blog.csdn.net/zhy_cheng/article/details/10286563 Excel作为一种有格式的文件,可以使用Java来对 ...

  9. 用 Eclipse 插件提高代码质量

    如果能在构建代码前发现代码中潜在的问题会怎么样呢?很有趣的是,Eclipse 插件中就有这样的工具,比如 JDepend 和 CheckStyle,它们能帮您在软件问题暴露前发现这些问题.在 让开发自 ...

  10. ubuntu下的fdisk用法

    Linux下的fdisk功能是极其强大的,用它可以划分出最复杂的分区,下面简要介绍一下它的用法: 对 于IDE硬盘,每块盘有一个设备名:对应于主板的四个IDE接口,设备名依次为:/dev/hda,/d ...