Esempio n. 1
0
        private static string ProcessRemoteControlWithUndo()
        {
            StringBuilder sb = new StringBuilder();

            RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo();

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

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

            remoteControlWithUndo.OnCommands[0]  = livingRoomLightOn;
            remoteControlWithUndo.OffCommands[0] = livingRoomLightOff;

            sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0));
            sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0));
            sb.AppendLine(remoteControlWithUndo.ToString());
            sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed());
            sb.AppendLine(remoteControlWithUndo.OffButtonWasPushed(0));
            sb.AppendLine(remoteControlWithUndo.OnButtonWasPushed(0));
            sb.AppendLine(remoteControlWithUndo.ToString());
            sb.AppendLine(remoteControlWithUndo.UndoButtonWasPushed());

            return(sb.ToString());
        }
Esempio n. 2
0
        private static string ProcessRemoteControlWithUndoComplex()
        {
            StringBuilder sb = new StringBuilder();

            RemoteControlWithUndo remoteControlUndo = new RemoteControlWithUndo();
            CeilingFan            ceilingFan1       = new CeilingFan("Living Room");

            remoteControlUndo.OnCommands[0]  = new CeilingFanMediumCommand(ceilingFan1);
            remoteControlUndo.OffCommands[0] = new CeilingFanOffCommand(ceilingFan1);

            remoteControlUndo.OnCommands[1]  = new CeilingFanHighCommand(ceilingFan1);
            remoteControlUndo.OffCommands[1] = new CeilingFanOffCommand(ceilingFan1);

            sb.AppendLine(remoteControlUndo.OnButtonWasPushed(0));
            sb.AppendLine(remoteControlUndo.OffButtonWasPushed(0));
            sb.AppendLine(remoteControlUndo.ToString());
            sb.AppendLine(remoteControlUndo.UndoButtonWasPushed());

            sb.AppendLine(remoteControlUndo.OnButtonWasPushed(1));
            sb.AppendLine(remoteControlUndo.ToString());
            sb.AppendLine(remoteControlUndo.UndoButtonWasPushed());

            return(sb.ToString());
        }