private static void Main(string[] args) { Manipulator manipulator = new Manipulator(); Console.WriteLine(manipulator.GetState()); RemoteController controller = new RemoteController(manipulator); controller.Up(10); Console.WriteLine(manipulator.GetState()); controller.Left(20); Console.WriteLine(manipulator.GetState()); controller.Right(10); Console.WriteLine(manipulator.GetState()); controller.Down(30); Console.WriteLine(manipulator.GetState()); controller.UndoLastCommand(); Console.WriteLine(manipulator.GetState()); controller.UndoLastCommand(); Console.WriteLine(manipulator.GetState()); controller.UndoLastCommand(); Console.WriteLine(manipulator.GetState()); controller.UndoLastCommand(); Console.WriteLine(manipulator.GetState()); Console.ReadLine(); }
/* * Reference: YouTube/Derek Banas * Allows you to store lists of code that is executed later time or many times * Client says I want a specific command to run when execute() is called on 1 of these encapsulated objects * An object called invoker transfers this command to another object called a receiver to execute the right code * */ static void Main(string[] args) { //setup the devices/receivers var lights = new Light(); var ac = new AirCondition(); //setup the concrete commands var lightsOn = new LightOn(lights); var lightsOff = new LightOff(lights); var acOn = new AcOn(ac); var acOff = new AcOff(ac); //setup the invoker/remote control var remoteController = new RemoteController(); remoteController.InsertNewOnCmd(lightsOn); remoteController.InsertNewOnCmd(acOn); remoteController.InsertNewOffCmd(lightsOff); remoteController.InsertNewOffCmd(acOff); //invoke the receiver remoteController.PressButtonOn(0); remoteController.PressButtonOn(1); remoteController.PressButtonOff(0); remoteController.PressButtonOff(1); Console.ReadLine(); }