随笔分类 -  dp

memento模式
摘要:http://www.cnblogs.com/w0w0/archive/2012/05/21/2512153.htmlhttp://www.cnblogs.com/mayvar/archive/2011/09/08/wanghonghua_201109080336.html 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <cstdlib> 5 #include <map> 6 #include <list> 7 #inclu 阅读全文

posted @ 2012-08-03 16:03 kakamilan 阅读(133) 评论(0) 推荐(0)

observe模式
摘要:1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <cstdlib> 5 #include <map> 6 #include <list> 7 #include <algorithm> 8 using namespace std; 9 typedef string State;10 11 class SecretaryBase;12 //抽象观察者13 class CObserverBase {14 protecte 阅读全文

posted @ 2012-08-02 16:29 kakamilan 阅读(428) 评论(0) 推荐(0)

state模式
摘要:http://www.cnblogs.com/graphicsme/archive/2011/12/09/2282657.htmlhttp://www.cnblogs.com/k-eckel/articles/204006.aspx 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <queue> 5 #include <set> 6 #include <algorithm> 7 #include <map> 8 # 阅读全文

posted @ 2012-07-26 22:01 kakamilan 阅读(261) 评论(0) 推荐(0)

strategy模式
摘要:讲的很清楚http://www.cnblogs.com/graphicsme/archive/2011/12/03/2274918.html 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <queue> 5 #include <set> 6 #include <algorithm> 7 #include <map> 8 #include <stack> 9 using namespace std;10 阅读全文

posted @ 2012-07-26 21:09 kakamilan 阅读(211) 评论(0) 推荐(0)

template模式
摘要:1 #include <iostream> 2 using namespace std; 3 class AbstractClass { 4 public: 5 AbstractClass() { 6 } 7 virtual ~AbstractClass() { 8 } 9 // 这个函数中定义了算法的轮廓10 void TemplateMethod();11 protected:12 // 纯虚函数,由派生类实现之13 virtual void PrimitiveOperation1() = 0;14 virtual void Pri... 阅读全文

posted @ 2012-07-25 23:55 kakamilan 阅读(170) 评论(0) 推荐(0)

proxy模式
摘要:1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <queue> 5 #include <set> 6 #include <algorithm> 7 #include <map> 8 #include <stack> 9 using namespace std;10 11 // 女学生类12 // 相当于client类13 class cSchoolGirl {14 private:15 string m 阅读全文

posted @ 2012-07-24 19:43 kakamilan 阅读(261) 评论(0) 推荐(0)

facade模式
摘要:有时不想对内部了解太多,只想获得一个接口,facade模式最好不过。 1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <queue> 5 #include <set> 6 #include <algorithm> 7 #include <map> 8 #include <stack> 9 using namespace std;10 11 class Subsystem1 {12 public:13 v 阅读全文

posted @ 2012-07-24 16:21 kakamilan 阅读(192) 评论(0) 推荐(0)

flyweight模式
摘要:1 #include <iostream> 2 #include <map> 3 #include <string> 4 #include <cstring> 5 #include <string.h> 6 #include <cstdlib> 7 using namespace std; 8 9 class Book { 10 public: 11 string GetPublish() { 12 return *m_publishCompany; 13 } 14 string GetWriter() { 15 r... 阅读全文

posted @ 2012-07-23 10:12 kakamilan 阅读(184) 评论(0) 推荐(0)

composite模式
摘要:1 #include <iostream> 2 #include <list> 3 using namespace std; 4 //公司类,提供接口,相当于compoent 5 class Company 6 { 7 public: 8 Company(string name) 9 { 10 m_name = name; 11 } 12 13 virtual ~Company() 14 {} 15 16 virtual void Add(Company *pCom) 17 {} 18 19 ... 阅读全文

posted @ 2012-07-21 15:39 kakamilan 阅读(232) 评论(0) 推荐(0)

decorator模式
摘要:1 #include <iostream> 2 using namespace std; 3 4 class compoent 5 { 6 public: 7 compoent(){} 8 virtual ~compoent(){} 9 10 virtual void Operation(){};11 };12 13 class concretecompoent:public compoent{14 virtual void Operation(){cout<<"I can only do AAAAAAAAAAAAAA!!!!\n";};15 16 阅读全文

posted @ 2012-07-19 16:23 kakamilan 阅读(180) 评论(0) 推荐(0)

adapter模式
摘要:1 #include <iostream> 2 using namespace std; 3 4 class target 5 { 6 public: 7 target(){} 8 virtual ~target(){} 9 10 virtual void Operation(){};11 };12 13 class adaptee{14 public:15 void special_work(){16 cout<<"only I can do!!\n";17 }18 };19 20 21 /*类适配器模式22 * 优点:可以重定义... 阅读全文

posted @ 2012-07-19 12:40 kakamilan 阅读(234) 评论(0) 推荐(0)

bridge模式
摘要:看了好几天,一直没想明白bridge模式到底怎么用,知道今天把四人帮的书翻出来,看到这样一句话,才恍然大悟,敲出来记录一下。“一般来讲,Implementor接口仅提供基本操作,而Abstraction则定义了基于这些基本操作的较高层次的操作。” 1 #include <iostream> 2 using namespace std; 3 4 5 // 为实现Abstraction定义的抽象基类,定义了实现的接口函数 6 class Implementor 7 { 8 public: 9 Implementor(){}10 virtual ~Implementor(){}1... 阅读全文

posted @ 2012-07-19 10:34 kakamilan 阅读(161) 评论(0) 推荐(0)

prototype模式
摘要:1 #include <iostream> 2 using namespace std; 3 4 class base 5 { 6 public: 7 int x; 8 base():x(3){} 9 virtual base* clone()=0;10 virtual ~base(){}11 void f(){12 cout<<x<<endl;13 }14 };15 16 17 class derieved : public base18 {19 public:20 21 derieved(){}22 vir... 阅读全文

posted @ 2012-07-16 20:17 kakamilan 阅读(147) 评论(0) 推荐(0)

23种设计模式汇总 (C++实现)
摘要:创建型模式链接builderhttp://www.cnblogs.com/kakamilan/archive/2012/07/16/2593412.htmlprototypehttp://www.cnblogs.com/kakamilan/archive/2012/07/16/2594128.html结构型模式链接bridgehttp://www.cnblogs.com/kakamilan/archive/2012/07/19/2598801.htmladapterhttp://www.cnblogs.com/kakamilan/archive/2012/07/19/2599062.htmld 阅读全文

posted @ 2012-07-16 13:33 kakamilan 阅读(244) 评论(0) 推荐(0)

builder模式
摘要:1 #include <iostream> 2 using namespace std; 3 4 5 struct person{ 6 int head; 7 int body; 8 }; 9 class Builder10 {11 public:12 virtual void BuildHead() {}13 virtual void BuildBody() {}14 virtual person* get()=0;15 virtual ~Builder(){}16 };17 //构造瘦人18 class ThinBuilder : pu... 阅读全文

posted @ 2012-07-16 13:19 kakamilan 阅读(211) 评论(0) 推荐(0)

导航