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