摘要: 下面以女娲造黑人,白人,黄种人的例子来介绍一下工厂模式。1.工厂的接口,相当于造人工厂总部。class IHumanFactory{public: IHumanFactory(void) { } ~IHumanFactory(void) { } virtual IHuman* CreateHuman() = 0;};2.造人各个的部门class WhiteHumanFactory: public IHumanFactory{public: WhiteHumanFactory(void) { } ~WhiteHum... 阅读全文
posted @ 2013-11-17 17:56 onlycxue 阅读(12837) 评论(0) 推荐(0) 编辑
摘要: 别人的博客再讲策略模式时都会讲三国,策略类就是赵云的锦囊,锦囊里装着若干妙计。在打仗时想要用什么妙计,直接从锦囊里去取。锦囊类:class context{public: context(IStrategy *isstrategy); ~context(); void Operate(void);private: IStrategy *m_strategy; };context::context(IStrategy *isstrategy):m_strategy(isstrategy){}context::~context(){}void context::Operate(void){ ... 阅读全文
posted @ 2013-11-17 16:53 onlycxue 阅读(1204) 评论(0) 推荐(0) 编辑