static void Main(string[] args) { //开店前的准备 Barbecuer boy = new Barbecuer(); Command bakeMuttonCommand1 = new BakeMuttonCommand(boy); Command bakeMuttonCommand2 = new BakeMuttonCommand(boy); Command bakeChickenWingCommand1 = new BakeChickenWingCommand(boy); Waiter girl = new Waiter(); //开门营业 girl.SetOrder(bakeMuttonCommand1); girl.Notify(); girl.SetOrder(bakeMuttonCommand2); girl.Notify(); girl.SetOrder(bakeChickenWingCommand1); girl.Notify(); Console.Read(); }
/* * 作者:Ai * 时间:2017.12.19 * 命令模式: * 将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化, * 对请求排队或记录请求日志,以及支持可撤销的操作。 * */ static void Main(string[] args) { /*下面写一个烧烤店的服务流程*/ //服务员 Waiter waiter = new Waiter(); //厨师 Chef chef = new Chef(); //来盘烤牛肉 waiter.AddOrder(Waiter.Com.Beef); waiter.AddOrder(Waiter.Com.Beef); waiter.AddOrder(Waiter.Com.Beef); //再来盘烤鸡翅 waiter.AddOrder(Waiter.Com.Chicken); //发现点多了,取消一盘牛肉 waiter.RemoveOrder(Waiter.Com.Beef); Console.WriteLine("----------------您的菜单如下------------"); //服务员让指定的厨师去做 waiter.Excute(chef); }
static void Main(string[] args) { //開店前的準備 Barbecuer boy = new Barbecuer(); Command bakeMuttonCommand1 = new BakeMuttonCommand(boy); Command bakeMuttonCommand2 = new BakeMuttonCommand(boy); Command bakeChickenWingCommand1 = new BakeChickenWingCommand(boy); Waiter girl = new Waiter(); //開門營業 顧客點菜 girl.SetOrder(bakeMuttonCommand1); girl.SetOrder(bakeMuttonCommand2); girl.SetOrder(bakeChickenWingCommand1); //點菜完閉,通知廚房 girl.Notify(); Console.Read(); }
static void Main(string[] args) { Barbecue cr = new Barbecue(); Shaokao c1 = new ChichenWinCommond(cr); Shaokao c2 = new SheepCommond(cr); Waiter w = new Waiter(); w.SetOrder(c1); w.SetOrder(c2); w.Notify(); }