pimpl idiom
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的更多相关文章
- Pimpl Idiom /handle body idiom
在读<Effective C++>和项目源代码时,看到pImpl Idiom.它可以用来降低文件间的编译依赖关系,通过把一个Class分成两个Class,一个只提供接口,另一个负责实现该接 ...
- pimpl idiom vs. bridge design pattern
http://stackoverflow.com/questions/2346163/pimpl-idiom-vs-bridge-design-pattern
- PIMPL(二)
文档下载 上一篇文档,PIMPL(一) 1 如何使用PIMPL 有多种方式实现PIMPL,这里按照<Effective C++>中介绍的方式. 1.1 基本步骤 假设原有Person如下: ...
- PIMPL(一)
1 参考 <effective C++> 条款31:将文件间的编译关系降至最低 PIMPL Idiom: http://c2.com/cgi/wiki?PimplIdiom 2 什么是PI ...
- [LintCode]——目录
Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...
- 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 ...
- PCurve - Curve on Surface
PCurve - Curve on Surface eryar@163.com Abstract. 本文通过给出曲面上曲线PCurve的定义来对OpenCascade中的Curve On Surfac ...
- callback的实现
Callback.h 继承层次 CallBack实现类 基类 第一层子类 第二层子类 第三层子类 SimpleRefCount CallbackImplBase CallbackImpl Functo ...
- C++11 现代C++风格的新元素--简介
C++11标准推出了很多有用的新特性,本文特别关注那些相比C++98更像是一门新语言的特性,理由是: 这些特性改变了编写C++程序使用的代码风格和习语[译注 1],通常也包括你设计C++函数库的方式. ...
随机推荐
- Jquery 获取第一个子元素
<ul> <li>John</li> <li>Karl</li> <li>Brandon</li></u ...
- vue路由使用踩坑点:当动态路由再使用路由name去匹配跳转时总是跳转到根路由的问题
闲话少说,直接问题: 之前我的路由时这么写的 { path:'/serverInfo/:id', name:'serverInfo', component:() => import('@/vie ...
- python3 UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f9e0' in position 230: illegal multibyte sequence
最近在保存微博数据到(csv文件)时报错: UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f9e0' in positio ...
- win7+iis7+asp+.net+php环境配置
一.我们先来配置一下iis: f 1. 点击[開始]->[控制面板]->点击[程序和功能]进入下一步 2. 然后,在左側点击[打开或关闭Windows功能].然后会跳出来一个框 3. 開始 ...
- (转)NGUI研究院之三种方式监听NGUI的事件方法
NGUI事件的种类很多,比如点击.双击.拖动.滑动等等,他们处理事件的原理几乎万全一样,本文只用按钮来举例. 1.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不 ...
- React Native for Android 热部署图片自己定义方案
情景 热部署时,我们期望升级包中包括js代码与图片资源. bundle的热部署网上已经有两种方案了,一种是用反射,一种是利用RN自带函数.将bundle初始化时直接放到指定文件夹下,之后通过替换bun ...
- Android实现Material Design风格的设置页面(滑动开关控件)
前言 本文链接 http://blog.csdn.net/never_cxb/article/details/50763271 转载请注明出处 參考了这篇文章 Material Design 风格的设 ...
- Android ShareSDKQQ 第三方登录so easy?
昨天群里有个群友看到我之前做的那个qq第三方登录怎么做的,于是乎思考了一下,还是决定写一篇博客记录下.事实上都不难的,事实上之前我又写到FaceBook的第三方登录不知道看下这Android集成Fac ...
- maven command to create your application
How do I make my first Maven project? We are going to jump headlong into creating your first Maven p ...
- spring源代码系列(一)sring源代码编译 spring源代码下载 spring源代码阅读
想对spring框架进行深入的学习一下,看看源码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建好开发环境吧. 环境搭建 sping源代码之前是svn管理,如今已经迁移到了github中了.新版本 ...