newwy
奋斗在IT路上的小蜗牛。一步一步往上爬,爬到小牛,在到大牛,然后是神牛,然后是犇,然后就可以离开IT行业,回归大自然了。 远离IT,珍爱生命!!! 记录学习的点滴。
/*********************************
*设计模式--命令实现
*C++语言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
using namespace std;
class Reciever
{
	public:
	Reciever(){}
	~Reciever(){}
	void Action(){cout<<"Reciever action.."<<endl;}
};
class Command
{
	public:
	Command(){}
	virtual ~Command(){};
	virtual void Exute() = 0;
	
};
class ConcreteCommand:public Command
{
	public:
	ConcreteCommand(Reciever * rev){this->_rev = rev;}
	~ConcreteCommand(){delete this->_rev;}
	void Excute(){_rev->Action();cout<<"ConcreteCommand...."<<endl;}
	private:
	Reciever *_rev;
};
class Invoker
{
	public:
	Invoker(Command *cmd){_cmd = cmd;}
	~Invoker(){delete _cmd;}
	void Invoke(){_cmd->Exute();}
	protected:
	Command *_cmd;
};
int main()
{
	Reciever *rev = new Reciever();
	Command *cmd = new ConcreteCommand(rev);
	Invoker *inv = new Invoker(cmd);
	inv->Invoke();
	return 0;
}

posted on 2010-10-18 23:38  newwy  阅读(259)  评论(0编辑  收藏  举报