/*********************************
*设计模式--命令实现
*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;
}

相关文章:

  • 2021-07-08
  • 2021-08-08
  • 2021-09-01
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2022-12-23
  • 2021-05-16
  • 2021-10-09
  • 2022-12-23
  • 2021-07-17
  • 2021-04-02
相关资源
相似解决方案