#include <iostream>
#include <vector>
using namespace std;
//
struct ILight
{
public:
virtual ~ILight() { }
virtual void Switch() = 0;
};
class CLightOn : public ILight
{
public:
virtual ~CLightOn() { }
virtual void Switch() { cout<<"on to off"<<endl; }
};
class CLightOff : public ILight
{
public:
virtual ~CLightOff() { }
virtual void Switch() { cout<<"off to on"<<endl; }
};
class CContext
{
public:
CContext() { }
void Switch(ILight *pLight) { pLight->Switch(); }
};
//
void main()
{
CContext context;
CLightOn lightOn;
context.Switch(&lightOn);
}
设计模式22:状态模式【行为型】
最新推荐文章于 2013-09-13 15:43:21 发布