PIMPL(private implementation或者pointer to implementation)
来源:互联网 发布:条码检查软件系统 编辑:程序博客网 时间:2024/05/29 18:24
一.不引入PIMPL技法
1.引入更多的头文件,降低编译速度 (main.cpp中引入y.h中带x.h,y.h中带x.h,两次引入x.h)
2.提高模块的耦合度(编译期,运行期)[如果X类大小改变,Y依赖于X实现,Y类需要重新编译
没有办法用到多态]
3.降低了接口的稳定程度
对于库的使用,方法不能改变
对于库的编译,动态库的变更,客户程序不用重新编译
[Y依赖于X实现,X改变,Y类需要重新编译]
//file y.h#include "x.h"class Y{public:void Fun();private:X x_;};//file y.cpp#include "y.h"void Y::Fun{ return x_.Fun(); }//file main.cpp #include "y.h"int main(void ) {Y y;y.Fun();}
二.PIMPL
1.PIMPL(private implementation或者pointer to implementation)也称为handle/body idiom
2.PIMPL背后的思想是把客户与所有关于类的私有部分的知识隔离开。避免其它类知道其内部结构
3.降低编译依赖,提高重新编译速度
4.接口和实现隔离
5.降低模块的耦合度
编译期
运行期
6.提高了接口的稳定程度
对于库的使用,方法不能改变
对于库的编译,动态库的变更,客户程序不用重新编译
//file y.hclass X;class Y{public:void Fun();private:X x_;};//file y.cpp#include "y.h"#include "x.h"void Y::Fun{ return x_->Fun(); }//file main.cpp #include "y.h"int main(void ) {Y y;y.Fun();}
阅读全文
1 0
- PIMPL(private implementation或者pointer to implementation)
- PIMPL实现String(pointer to implementation)
- PIMPL (Private Implementation)
- 关于PIMPL (Private Implementation)
- 设计模式--Pimpl(pointer to implementation 指向实现的指针)
- Private implementation slots
- 减少编译时间:pointer to implementation(Impl设计模式)
- Implementation
- implementation
- 设计模式(五)桥接模式Bridge == Pointer To Implementation
- HeapSort implementation (Introduction to Algorithms)
- introduction-to-reinforcement-learning-implementation
- "Programming to an Interface, not an Implementation"
- Quick sort implementation (Introduction to Algorithms)
- Brief Intro to KVC Design and Implementation
- A practical approach to Connection Point implementation
- Item22 When using the Pimpl, define specific member functions in the implementation file
- Implementation Patterns
- 袋鼠妈妈找孩子 2017 华东师范大学网赛
- spring事务(声明式和编程式)
- 两会花絮:上会外国记者也豁出去了
- 《JavaScript权威指南(第六版)》.(美)David.Flanagan.中文扫描版.pdf
- 统计学习方法
- PIMPL(private implementation或者pointer to implementation)
- 凤凰网、大公网等媒体争相报道汪国新委员:加强手机安全,保护公民信息
- python异常
- HTML5 语义化
- c++primer 练习 p99 3.4.1 迭代器 大写 cbegin 随机函数
- SpringMVC 使用注解完成登录拦截
- 【编程素质】算法-棋盘覆盖
- 手机震动效果实现
- javaScript 的值传递