![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
letterwuyu
Linux c c++ python java
分布式存储&消息队列&计算
展开
-
Singleton 单例模式 -- 饿汉
/*直接照着boost库的一个比较广泛的单例模式写的,一字不错,boost有很多单例模式可以研究 *最近项目用到一个单例模式,是教科书使得,'懒汉模式',这个是'饿汉模式',优点是在main函数 *开始之前就构造实例了,这样是线程安全的,效率比较高,毕竟不是在堆上创建的一般单例不需要考虑内存的泄露,静态变量生存周期 *和程序运行周期是一样的,知道程序结束而释放,。。。总之没必要为了一个单例模原创 2017-09-22 18:42:17 · 266 阅读 · 0 评论 -
builder模式实例
#include <iostream> #include <algorithm> #include <vector> #include <list> #include <memory> //产品抽象类 class Product{ public: virtual void AddPart(const std::string& str) = 0; virtual ~Product() = 0; public: virtual void DoAction() const = 0; }; Product:原创 2017-10-27 12:09:24 · 332 阅读 · 0 评论 -
bridge模式实例
#include //画笔抽象类 class Pen { public: virtual ~Pen(); public: virtual void PrintProstect() const = 0; virtual void PrintContext() const = 0; }; Pen::~Pen() {} //画笔A class PenA : public Pen { publ原创 2017-10-27 17:12:53 · 577 阅读 · 0 评论 -
Builder模式的误区:将复杂对象的构建进行封装,就是Builder模式了吗?
http://www.cnblogs.com/happyhippy/archive/2010/09/01/1814287.html 最近重读GOF的《设计模式》,读到Builder模式的时候,发现还是不能领悟;网上搜了下其他人的解释,发现很多人都用错了Builder模式,结构形似Builder,实际上却更像Template、或者Factory Method,或者四不像,并没有体现出Buil转载 2017-10-26 21:08:33 · 283 阅读 · 0 评论