static void Main(string[] args) { //创建命令管理者 Invoker invoker = new Invoker(); //创建执行者和命令 并指定命令执行者 Receiver r = new Receiver(); //执行者 ConcreteCommand c1 = new ConcreteCommand(); //创建命令 c1.Receiver = r; //指定执行者 ConcreteCommandB c2 = new ConcreteCommandB(); c2.Receiver = r; invoker.SetCommand(c1); invoker.SetCommand(c2); invoker.SetCommand(c1); invoker.ExecuteCommand(); Console.WriteLine("------------------------"); invoker.RemoveCommand(c2); invoker.ExecuteCommand(); Console.ReadKey(); }
static void Main(string[] args) { Account account = new Account(); Command commandIn = new MoneyInCommand(account, 500); Invoker invoker = new Invoker(); invoker.SetCommand(commandIn); invoker.ExecuteCommand(); Console.WriteLine("The current amount is " + account.GetTotalAmout()); Command commandOut = new MoneyOutCommand(account, 300); invoker.SetCommand(commandOut); invoker.ExecuteCommand(); Console.WriteLine("The current amount is " + account.GetTotalAmout()); Console.ReadKey(); }
static void Main(string[] args) { Receiver r = new Receiver(); Command c = new ConcreteCommand(r); Invoker i = new Invoker(); i.SetCommand(c); i.ExecuteCommand(); }
static void Main(string[] args) { Receiver receiver = new Receiver(); Command command = new ConcreteCommand(receiver); Invoker invoke = new Invoker(); invoke.SetCommand(command); invoke.ExecuteCommand(); Console.ReadKey(); }
static void Main(string[] args) { Receiver receiver = new Receiver(); Command command =new ConcreteCommand(receiver); Invoker invoke = new Invoker(); invoke.SetCommand(command); invoke.ExecuteCommand(); Console.ReadKey(); }
private static void Main(string[] args) { Receiver r = new Receiver(); Command c = new ConcreteCommand(r); Invoker i = new Invoker(); // Set and execute command i.SetCommand(c); i.ExecuteCommand(); Console.Read(); }
//客户端代码: 创建一个具体命令对象并设定它的接受者 static void Main(string[] args) { //烤肉师傅 Receiver r = new Receiver(); //服务员 Command c = new ConcreteCommand(r); //顾客 Invoker i = new Invoker(); i.SetCommand(c); i.ExecuteCommand(); }
static void Main(string[] args) { Receiver r = new Receiver(); Command c = new ConcreteCommand(r); Invoker i = new Invoker(); // Set and execute command i.SetCommand(c); i.ExecuteCommand(); Console.Read(); }