示例#1
0
        static void Main(string[] args)
        {
            var remoteControl = new RemoteControlWithUndo();

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

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

            remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff);

            remoteControl.OnButtonWasPressed(0);
            remoteControl.OffButtonWasPressed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPressed();
            remoteControl.OffButtonWasPressed(0);
            remoteControl.OnButtonWasPressed(0);
            Console.WriteLine(remoteControl);
            remoteControl.UndoButtonWasPressed();

            Console.ReadLine();
        }
示例#2
0
        public static void RunRemoteControlWithUndo()
        {
            var remote         = new RemoteControlWithUndo();
            var light          = new Light();
            var lightOn        = new LightOnCommand(light);
            var lightOff       = new LightOffCommand(light);
            var stereo         = new Stereo();
            var stereoOnWithCD = new StereoOnWithCDCommand(stereo);
            var stereoOff      = new StereoOffCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, stereoOnWithCD, stereoOff);
            System.Console.WriteLine(remote);

            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);
            remote.UndoButtonWasPressed();

            remote.OnButtonWasPressed(1);
            remote.UndoButtonWasPressed();
            remote.OffButtonWasPressed(1);
        }