您的位置:首页 > 其它

Command 命令模式

2010-12-07 14:26 253 查看
#include <cstdlib>
#include <iostream>

using namespace std;
class Reciver
{
public:
virtual void Execute() = 0;
};
class ReciverConcrete:public Reciver
{
public:
virtual void Execute(){cout<<"ReciverConcrete do sth."<<endl;}
};
class Command
{
Reciver* pRecv;
public:
Command(Reciver* p):pRecv(p){}
~Command(){delete pRecv;}
void Execute(){pRecv->Execute();}
};
class Invoker
{
Command* pCom;
public:
Invoker(Command* p):pCom(p){}
~Invoker(){delete pCom;}
void Invoke(){pCom->Execute();}
};
void Do(Invoker* pInv)
{
pInv->Invoke();
delete pInv;
}
int main(int argc, char *argv[])
{
Do(new Invoker(new Command(new ReciverConcrete)));
system("PAUSE");
return EXIT_SUCCESS;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: