命令模式
来源:互联网 发布:发票统计软件 编辑:程序博客网 时间:2024/05/26 15:58
#include <iostream>
#include <string>
//#include <afx.h>
#include <vector>
#include <list>
using namespace std;
class Barbecuer
{
public:
void BakeButton()
{
cout<<"烤羊肉串\n";
}
void BakeChickenWing()
{
cout<<"烤鸡翅\n";
}
};
class Command
{
protected:
Barbecuer *receiver;
public:
Command(Barbecuer *receiver)
{
this->receiver = receiver;
}
virtual void ExcuteCommand(){};
};
class BakeMuttonCommand:public Command
{
public:
BakeMuttonCommand(Barbecuer *receiver):Command(receiver){};
virtual void ExcuteCommand()
{
receiver->BakeButton();
}
};
class BakeChickenWingCommand:public Command
{
public:
BakeChickenWingCommand(Barbecuer *receiver):Command(receiver){};
virtual void ExcuteCommand()
{
receiver->BakeChickenWing();
}
};
class Waiter
{
list<Command *>CI;
list<Command *>::iterator i;
public:
void SetOrder(Command *command)
{
CI.push_back(command);
}
void Notify()
{
for (i = CI.begin(); i != CI.end(); ++i)
(*i)->ExcuteCommand();
}
};
int main()
{
Barbecuer man;
BakeMuttonCommand muttoncommand1(&man);
BakeMuttonCommand muttoncommand2(&man);
BakeChickenWingCommand chickenwingcommand1(&man);
Waiter girl;
girl.SetOrder(&muttoncommand1);
girl.SetOrder(&muttoncommand2);
girl.SetOrder(&chickenwingcommand1);
girl.Notify();
cout<<"\nOK\n";
return 1;
}
#include <string>
//#include <afx.h>
#include <vector>
#include <list>
using namespace std;
class Barbecuer
{
public:
void BakeButton()
{
cout<<"烤羊肉串\n";
}
void BakeChickenWing()
{
cout<<"烤鸡翅\n";
}
};
class Command
{
protected:
Barbecuer *receiver;
public:
Command(Barbecuer *receiver)
{
this->receiver = receiver;
}
virtual void ExcuteCommand(){};
};
class BakeMuttonCommand:public Command
{
public:
BakeMuttonCommand(Barbecuer *receiver):Command(receiver){};
virtual void ExcuteCommand()
{
receiver->BakeButton();
}
};
class BakeChickenWingCommand:public Command
{
public:
BakeChickenWingCommand(Barbecuer *receiver):Command(receiver){};
virtual void ExcuteCommand()
{
receiver->BakeChickenWing();
}
};
class Waiter
{
list<Command *>CI;
list<Command *>::iterator i;
public:
void SetOrder(Command *command)
{
CI.push_back(command);
}
void Notify()
{
for (i = CI.begin(); i != CI.end(); ++i)
(*i)->ExcuteCommand();
}
};
int main()
{
Barbecuer man;
BakeMuttonCommand muttoncommand1(&man);
BakeMuttonCommand muttoncommand2(&man);
BakeChickenWingCommand chickenwingcommand1(&man);
Waiter girl;
girl.SetOrder(&muttoncommand1);
girl.SetOrder(&muttoncommand2);
girl.SetOrder(&chickenwingcommand1);
girl.Notify();
cout<<"\nOK\n";
return 1;
}
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 命令模式
- 关于oracle的where条件有特殊符号的处理
- Linux下chkconfig命令详解
- 剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)
- Android应用开发之(字符串替换与文本颜色改变方案)
- 数据库索引的作用和优点缺点
- 命令模式
- 页面级别性能测试分析
- linux指令--more 文件名
- 如何为resin的jvm-default.log瘦身
- 查看某进程开启的文件数
- vc6.0配置boost正则表达式库
- Redis 主从设置以及注意的问题
- javascript中href和replace比较
- 关于性能测试的收获