static void Main(string[] args) { //基本结构 Receiver r = new Receiver(); Command command = new ConcreteCommand(r); Invoke i = new Invoke(); i.SetCommand(command); i.ExcuteCommand(); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("***Command Pattern Demo***\n"); /*Client holds both the Invoker and Command Objects*/ Invoke invoker = new Invoke(); Receiver intendedreceiver = new Receiver(); MyUndoCommand undoCmd = new MyUndoCommand(intendedreceiver); invoker.SetCommand(undoCmd); invoker.ExecuteCommand(); MyRedoCommand redoCmd = new MyRedoCommand(intendedreceiver); invoker.SetCommand(redoCmd); invoker.ExecuteCommand(); Console.ReadKey(); }
static void Main(string[] args) { WashMachine washMachine = new WashMachine(); Stereo stereo = new Stereo(); Invoke invoke = new Invoke(); invoke.SetCommand(new OffStereo(stereo)); invoke.ExecuteCommand(); invoke.SetCommand(new OnStereo(stereo)); invoke.ExecuteCommand(); invoke.SetCommand(new OnWasMachine(washMachine)); invoke.ExecuteCommand(); invoke.SetCommand(new OffWashMachine(washMachine)); invoke.ExecuteCommand(); Console.ReadKey(); }