1 Star 0 Fork 621

holiday/DesignPattern

forked from Micooz/DesignPattern 
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CommandPattern.cpp 802 Bytes
一键复制 编辑 原始数据 按行查看 历史
Micooz 提交于 2014-10-08 22:20 +08:00 . 加入命令模式
#include <iostream>
using namespace std;
class Reciever {
public:
void Action() {
cout << "Reciever::Action..." << endl;
}
};
class Command {
public:
virtual ~Command() { }
virtual void Excute() = 0;
};
class ConcreteCommand :public Command {
public:
ConcreteCommand(Reciever *rev) {
_rev = rev;
}
void Excute() {
_rev->Action();
}
private:
Reciever *_rev;
};
class Invoker {
public:
Invoker(Command* cmd) {
_cmd = cmd;
}
void Invoke() {
_cmd->Excute();
}
private:
Command *_cmd;
};
int main() {
Reciever *rev = new Reciever();
Command* cmd = new ConcreteCommand(rev);
Invoker *inv = new Invoker(cmd);
inv->Invoke();
delete rev;
delete cmd;
delete inv;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/holiday321/DesignPattern.git
git@gitee.com:holiday321/DesignPattern.git
holiday321
DesignPattern
DesignPattern
master

搜索帮助