摘要:
【1】什么是适配器模式?将一个类的接口转换成客户希望的另外一个接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以在一起工作。【2】适配器模式的代码示例:代码示例如下1:#include #include using namespace std;class Adaptee{pub... 阅读全文
posted @ 2015-05-27 22:26
南哥的天下
阅读(168)
评论(0)
推荐(0)
摘要:
【1】什么是备忘录模式?在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态。这样就可以将该对象恢复到原先保存的状态。【2】备忘录模式的代码示例:代码示例如下:#include #include #include using namespace std;class Memo{p... 阅读全文
posted @ 2015-05-27 22:24
南哥的天下
阅读(328)
评论(0)
推荐(0)
摘要:
【1】什么是组合模式?将对象组合成树形结构以表示“部分整体”的层次结构。组合模式使得用户对单个对象和组合对象的使用具有一致性。【2】组合模式代码示例:代码示例:#include #include #include using namespace std;class Component{public:... 阅读全文
posted @ 2015-05-27 22:23
南哥的天下
阅读(199)
评论(0)
推荐(0)
摘要:
【1】什么是迭代器模式?【2】迭代器模式代码示例:代码示例:#include #include using namespace std;class Iterator;class Aggregate{public: virtual Iterator *createIterator() = 0;}... 阅读全文
posted @ 2015-05-27 22:21
南哥的天下
阅读(115)
评论(0)
推荐(0)
摘要:
一、懒汉模式 即第一次调用该类实例的时候才产生一个新的该类实例,并在以后仅返回此实例。 需要用锁,来保证其线程安全性:原因:多个线程可能进入判断是否已经存在实例的if语句,从而non thread safety。 使用double-check来保证thread safety。但是如果处理大量数据时, 阅读全文
posted @ 2015-05-27 22:20
南哥的天下
阅读(203)
评论(0)
推荐(0)
摘要:
【1】什么是桥接模式?【2】桥接模式的代码示例示例代码:#include #include using namespace std;class HandsetSoft{public: virtual void run() = 0;};class HandsetGame : public Han... 阅读全文
posted @ 2015-05-27 22:14
南哥的天下
阅读(209)
评论(0)
推荐(0)
摘要:
【1】什么是命令模式?命令模式:【2】命令模式的代码示例:代码示例:#if 0#include #include using namespace std;/* * 运算基类 */class Operation{public: double numberA; double numberB;... 阅读全文
posted @ 2015-05-27 22:13
南哥的天下
阅读(348)
评论(0)
推荐(0)
摘要:
【1】什么是责任链模式?责任链模式:【2】责任链模式的代码示例:代码示例:#include#includeusing namespace std;class Request{public: string requestType; string requestContent; int... 阅读全文
posted @ 2015-05-27 22:12
南哥的天下
阅读(186)
评论(0)
推荐(0)
摘要:
【1】什么是中介者模式?中介者模式:【2】中介者模式代码示例:代码示例:#include#include using namespace std;class Mediator;class ConcreteColleague1;class ConcreteColleague2;class Collea... 阅读全文
posted @ 2015-05-27 22:11
南哥的天下
阅读(147)
评论(0)
推荐(0)
摘要:
【1】什么是享元模式?享元模式:【2】享元模式的代码示例:#include #include #include using namespace std;class Flyweight{public: virtual void operation(int) = 0;};class Concret... 阅读全文
posted @ 2015-05-27 22:09
南哥的天下
阅读(173)
评论(0)
推荐(0)
浙公网安备 33010602011771号