![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
设计模式
文章平均质量分 71
Andy-Action-Now
这个作者很懒,什么都没留下…
展开
-
单例模式
意图: 使类的对象成为系统中唯一的实例 实现分析: 1. 任何new 的过程得到的 对象都是一样的, 即 : Object *m_obj1 = new Object(); Object *m_obj2 = new Object(); 如果采用这种方式,则 m_obj1 != m_obj2, 即不能采用这种创建对象的方式。 2. 类中的static 变量在原创 2013-10-13 17:15:22 · 719 阅读 · 0 评论 -
组合模式
#include #include #include using namespace std; class Component { public: Component(string name):name(name){} virtual void Add(Component* c) = 0; virtual void Remove(Component* c) = 0;原创 2014-10-01 17:01:08 · 527 阅读 · 0 评论 -
simple factory
#include using namespace std; template class BaseOper { public: void SetParam(const T& a, const T& b) { this->a = a; this->b = b; } virtual T GetResult() = 0; protected: T a; T b; };原创 2016-07-23 14:41:40 · 342 阅读 · 0 评论 -
factory model
#include using namespace std; template class BaseOper { public: void SetParam(const T& a, const T& b) { this->a = a; this->b = b; } virtual T GetResult() = 0; protected: T a; T b; }; t原创 2016-07-23 14:49:59 · 509 阅读 · 0 评论 -
single model
#include #include using namespace std; class Single { public: static Single & GetInstance() { static Single _obj; return _obj; } void Print() { cout << "hello world : " << endl; } prot原创 2016-07-23 15:06:31 · 638 阅读 · 0 评论 -
proxy model
#include #include using namespace std; /************************************************************************/ /* 例如: /* 小明要给韩梅梅送花,但是小明不认识韩梅梅,但是李雷是韩梅梅的好朋友,小明和李雷是 /* 好朋友, 所以小明可以通过李雷(代理)送花给韩梅梅 /*原创 2016-07-23 16:45:58 · 687 阅读 · 0 评论 -
template model
#include #include using namespace std; /************************************************************************/ /* 模板模式:定义一个操作中的骨架,将一些延迟操作放到子类中 /* 模板模式使子类可以不改变一个算法的骨架即可重定义该算法中的某些特定的步骤 /********原创 2016-07-23 17:21:02 · 549 阅读 · 0 评论 -
command model
#include #include #include using namespace std; /************************************************************************/ /* 命令模式,将一个请求封装成一个对象,从而使你可以用不同的请求对客户进行参数化; /* 对请求排队和记录请求日志, 以及支持可撤销的操作。 /原创 2016-07-23 18:23:34 · 532 阅读 · 0 评论