
设计模式学习笔记
文章平均质量分 67
寂寞的泡面
我只是一个快乐的程序员。
展开
-
FactoryPattern——创建型模式
<br /><br />以下代码已经在VC6.0中测试运行通过。<br />factory.h<br />#ifndef _FACTORY_H_ #define _FACTORY_H_ #include <string> using namespace std; class Fruit; class Factory { protected: Factory(){}; public: virtual ~Factory() = 0; virtual Fruit* Crea原创 2011-03-20 19:56:00 · 2007 阅读 · 0 评论 -
Flyweight模式——结构型模式
<br /><br /> <br />flyweight.h<br />#ifndef _FLY_WEIGHT_H_ #define _FLY_WEIGHT_H_ #include <string> using namespace std; class Flyweight { protected: Flyweight(string intrinsic_state); public: virtual void Operation(const string& extrinsic_s原创 2011-04-05 09:12:00 · 2413 阅读 · 0 评论 -
Strategy模式——行为模式
<br /><br /> <br />strategy.h<br />#ifndef _STRATEGY_H_ #define _STRATEGY_H_ class Strategy { public: virtual ~Strategy(); virtual void AlgrithmInterface()=0; protected: Strategy(); }; class ConcreteStrategyA:public Strategy { public:原创 2011-03-31 21:55:00 · 2147 阅读 · 0 评论 -
Template模式——行为模式
<br /><br />template.h<br />#ifndef _TEMPLATE_H_ #define _TEMPLATE_H_ class AbstractClass { public: virtual ~AbstractClass(); void TemplateMethod(); protected: AbstractClass(); virtual void PrimitiveOperation1()=0; virtual void PrimitiveOp原创 2011-03-28 17:50:00 · 2031 阅读 · 0 评论 -
Proxy模式——结构性模式
<br /><br /> <br />proxy.h<br />#ifndef _PROXY_H_ #define _PROXY_H_ class Subject { public: virtual ~Subject(); virtual void Request()=0; protected: Subject(); }; class ConcreteSubject:public Subject { public: ConcreteSubject(); ~Con原创 2011-03-27 15:21:00 · 2030 阅读 · 0 评论 -
Facade模式——结构型模式
外部与一个子系统的通信必须通过一个统一的门面(Facade)对象进行,这就是门面模式。facade.h#ifndef _FACADE_H_ #define _FACADE_H_ class SubSystem1; class SubSystem2; class Facade { public: ~Facade(); static Facade* Instance(); void OperationWrapper(); protected: Facade(); priv原创 2011-03-26 01:28:00 · 2095 阅读 · 0 评论 -
Bridge模式——结构型模式
<br /><br /> <br />tank.h<br />#ifndef _TANK_H_ #define _TANK_H_ class TankImpl; class Tank { public: virtual ~Tank(); virtual void shot()=0; virtual void run()=0; protected: Tank(); }; class ChinaTank:public Tank { public: ChinaT原创 2011-03-23 19:33:00 · 1828 阅读 · 0 评论 -
Bridge模式——结构型模式
<br /><br /> <br />tank.h<br />#ifndef _TANK_H_ #define _TANK_H_ class TankImpl; class Tank { public: virtual ~Tank(); virtual void shot()=0; virtual void run()=0; protected: Tank(); }; class ChinaTank:public Tank { public: ChinaT原创 2011-03-23 19:51:00 · 2012 阅读 · 0 评论 -
Adapter模式——结构型模式
<br /><br /> <br />adapter.h<br />#ifndef _ADAPTER_H_ #define _ADAPTER_H_ class Target { public: Target(); virtual ~Target(); virtual void Request(); }; class Adaptee { public: Adaptee(); ~Adaptee(); void SpecificRequest(); }; c原创 2011-03-24 20:29:00 · 2009 阅读 · 0 评论 -
Singleton模式——创建型模式
<br /><br /> <br />Singleton.h<br />#ifndef _SINGLETON_H_ #define _SINGLETON_H_ class Singleton { public: virtual ~Singleton(); static Singleton* Instance(); protected: Singleton(); private: static Singleton* m_instance; }; #endif<br />原创 2011-03-22 22:09:00 · 2124 阅读 · 4 评论 -
AbstractFactory模式——创建型模式
<br /><br />factory.h<br />#ifndef _ABSTRACT_FACTORY_H_ #define _ABSTRACT_FACTORY_H_ class Product; class AbstractFactory { protected: AbstractFactory(); public: virtual ~AbstractFactory()=0; virtual Product* CreateProductA()=0; virtual P原创 2011-03-21 12:10:00 · 1979 阅读 · 0 评论 -
Observer模式——行为模式
<br /><br />observer.h<br />#ifndef _OBSERVER_H_ #define _OBSERVER_H_ #include <string> using namespace std; typedef string State; class Subject; class Observer { public: virtual ~Observer(); virtual void Update(Subject* sub) = 0; vir原创 2011-04-15 20:14:00 · 2936 阅读 · 6 评论