static void Main(string[] args)
        {
            var remote = new RemoteControlWithUndo();

            var livingRoomLight = new Light("Living Room");

            var livingRoomLightOn  = new LightOnCommand(livingRoomLight);
            var livingRoomLightOff = new LightOffCommand(livingRoomLight);

            remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff);

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);

            Console.WriteLine(remote);

            remote.UndoButtonWasPushed();
            remote.OffButtonWasPushed(0);
            remote.OnButtonWasPushed(0);

            Console.WriteLine(remote);

            remote.UndoButtonWasPushed();

            var ceilingFan = new CeilingFan("Living Room");

            var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            var ceilingFanHigh   = new CeilingFanHighCommand(ceilingFan);
            var ceilingFanOff    = new CeilingFanOffCommand(ceilingFan);

            remote.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remote.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            remote.OnButtonWasPushed(0);
            remote.OffButtonWasPushed(0);

            Console.WriteLine(remote);

            remote.UndoButtonWasPushed();
            remote.OnButtonWasPushed(1);

            Console.WriteLine(remote);

            remote.UndoButtonWasPushed();

            // Wait for user
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            RemoteControlWithUndo remoteControl = new RemoteControlWithUndo();

            Light livingRoomLight = new Light("Living Room");

            LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight);
            LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight);

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);

            Console.WriteLine(remoteControl);

            remoteControl.UndoButtonWasPushed();
            remoteControl.OffButtonWasPushed(0);
            remoteControl.OnButtonWasPushed(0);

            Console.WriteLine(remoteControl);

            remoteControl.UndoButtonWasPushed();

            CeilingFan ceilingFan = new CeilingFan("Living Room");

            CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan);
            CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan);
            CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

            remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff);
            remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff);

            remoteControl.OnButtonWasPushed(0);
            remoteControl.OffButtonWasPushed(0);

            Console.WriteLine(remoteControl);

            remoteControl.UndoButtonWasPushed();
            remoteControl.OnButtonWasPushed(1);

            Console.WriteLine(remoteControl);

            remoteControl.UndoButtonWasPushed();

            // Wait for user
            Console.ReadKey();
        }