Fork me on GitHub

随笔分类 -  设计模式

摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 class User 11 { 12 public: 13 User(string strName): m_strName(strName) 14 ... 阅读全文
posted @ 2017-05-31 23:12 码农的逼格 阅读(310) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 class Colleague; 7 8 class Mediator 9 { 10 public: 11 virtual void Send(string strMessage, Colleague* pstColleag... 阅读全文
posted @ 2017-05-24 22:49 码农的逼格 阅读(354) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 7 class Handler 8 { 9 public: 10 Handler(Handler* pstHandler): m_pstHandler(pstHandler) 11 { 12 13 ... 阅读全文
posted @ 2017-05-23 23:11 码农的逼格 阅读(285) 评论(0) 推荐(0)
摘要:1 [root@ ~/learn_code/design_pattern/19_order]$ cat order.cpp 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 class Receiver... 阅读全文
posted @ 2017-05-22 20:39 码农的逼格 阅读(385) 评论(0) 推荐(0)
摘要:参考: http://www.cnblogs.com/jiese/p/3164940.html http://design-patterns.readthedocs.io/zh_CN/latest/structural_patterns/bridge.html 阅读全文
posted @ 2017-05-22 20:37 码农的逼格 阅读(862) 评论(0) 推荐(2)
摘要:组合模式:将对象组合成树形结构以表示“部分-整体”的层次结构。 组合模式使得用户对单个对象和组合对象的使用具有一致性。 是一种结构型模式 使用场景: 1、用于对象的部分-整体层次结构,如树形菜单、文件夹菜单、部门组织架构图等; 2、对用户隐藏组合对象与单个对象的不同,使得用户统一地使用组合结构中的所 阅读全文
posted @ 2017-05-19 20:22 码农的逼格 阅读(825) 评论(0) 推荐(1)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 class STMemento 8 { 9 private: 10 int iVitality; 11 public: 12 STMemento(){} 13 STM... 阅读全文
posted @ 2017-05-17 19:47 码农的逼格 阅读(809) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 7 class STTarget 8 { 9 public: 10 virtual void Request() 11 { 12 13 } 14 15 vir 阅读全文
posted @ 2017-05-16 22:17 码农的逼格 阅读(264) 评论(0) 推荐(0)
摘要:1 /////////context.cpp 2 #include "context.h" 3 4 void STContext::ChangeState(STState* pstState) 5 { 6 m_pstState = pstState; 7 } 8 9 void STContext::request() 10... 阅读全文
posted @ 2017-05-15 22:13 码农的逼格 阅读(335) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 class STSubject; 10 11 //观察者 12 class STObserver 13 { 14 public: 15 virtual void Update(... 阅读全文
posted @ 2017-05-12 22:14 码农的逼格 阅读(465) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 class STSystemA 7 { 8 public: 9 void OperationA() 10 { 11 coutOperationA(); 53 m_... 阅读全文
posted @ 2017-05-12 09:39 码农的逼格 阅读(269) 评论(0) 推荐(0)
摘要:参考:http://design-patterns.readthedocs.io/zh_CN/latest/creational_patterns/builder.html 阅读全文
posted @ 2017-05-10 09:47 码农的逼格 阅读(918) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 7 class STAbstractProductA 8 { 9 public: 10 virtual void use() = 0; 11 }; 12 13 class STProductA1: publi... 阅读全文
posted @ 2017-05-08 20:36 码农的逼格 阅读(300) 评论(0) 推荐(0)
摘要:模板模式:定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤。 模板模式通过把不变的行为搬移到超类,去除子类中的重复代码来体现它的优势。 通过继承和多态来实现。 行为型模式。 spp业务框架中的server_task(CSer 阅读全文
posted @ 2017-05-05 21:28 码农的逼格 阅读(806) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 class CPrototype 7 { 8 public: 9 CPrototype() 10 { 11 12 } 13 CPrototype(int iAge): m_iAge(iAge) 14 ... 阅读全文
posted @ 2017-05-04 20:32 码农的逼格 阅读(407) 评论(0) 推荐(0)
摘要:参考:http://design-patterns.readthedocs.io/zh_CN/latest/creational_patterns/factory_method.html 阅读全文
posted @ 2017-05-03 09:09 码农的逼格 阅读(267) 评论(0) 推荐(0)
摘要:参考:http://design-patterns.readthedocs.io/zh_CN/latest/structural_patterns/proxy.html 阅读全文
posted @ 2017-04-28 21:20 码农的逼格 阅读(623) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 class Component 7 { 8 public: 9 virtual void operation() = 0; 10 }; 11 12 class ConcreteComponentA: public Comp... 阅读全文
posted @ 2017-04-27 21:40 码农的逼格 阅读(394) 评论(0) 推荐(0)
摘要:程序优化是用于消除程序中大量的if else这种判断语句 阅读全文
posted @ 2017-04-26 09:16 码农的逼格 阅读(268) 评论(0) 推荐(2)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 7 class COperator 8 { 9 public: 10 virtual double GetResult()=0; 11 12 public: 13 COperator() 14 { 15 ... 阅读全文
posted @ 2017-04-21 21:05 码农的逼格 阅读(308) 评论(0) 推荐(0)