static void TryRemoteControlWithMacroCommand() { Console.WriteLine("\n----- Remote control with party! -----\n"); var remoteControl = new RemoteControl(); var light = new Light("Living room"); var stereo = new Stereo("Living room"); var lightOn = new LightsOnCommand(light); var lightOff = new LightsOffCommand(light); var stereoOn = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffWithCDCommand(stereo); var partyOn = new ICommand[] { lightOn, stereoOn }; var partyOff = new ICommand[] { lightOff, stereoOff }; var partyOnCommand = new MacroCommand(partyOn); var partyOffCommand = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnCommand, partyOffCommand); Console.WriteLine(remoteControl); Console.WriteLine("\n-- Party on --\n"); remoteControl.PressOnButton(0); Console.WriteLine("\n-- Party off --\n"); remoteControl.PressOffButton(0); }
static void TryRemoteControl() { var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living room"); var kitchenLight = new Light("Kitchen"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living room"); var livingRoomLightOnCommand = new LightsOnCommand(livingRoomLight); var livingRoomLightOffCommand = new LightsOffCommand(livingRoomLight); var kitchenLightOnCommand = new LightsOnCommand(kitchenLight); var kitchenLightOffCommand = new LightsOffCommand(kitchenLight); remoteControl.SetCommand(0, livingRoomLightOnCommand, livingRoomLightOffCommand); remoteControl.SetCommand(1, kitchenLightOnCommand, kitchenLightOffCommand); Console.WriteLine(remoteControl); remoteControl.PressOnButton(0); remoteControl.PressOffButton(0); remoteControl.PressOnButton(1); remoteControl.PressOffButton(1); }
public static void UseCommandPattern(IView view) { RemoteControl remote = new RemoteControl(view); Light livingRoomLight = new Light(view, "Living Room"); Light kitchenLight = new Light(view, "Kitchen"); //CeilingFan ceilingFan = new CeilingFan(view, "Kitchen"); Garage garage = new Garage(view); Stereo stereo = new Stereo(view); ICommand livigRommLightOn = new LightOnCommand(livingRoomLight); ICommand livigRommLightOff = new LightsOffCommand(livingRoomLight); ICommand KitchenLightOn = new LightOnCommand(kitchenLight); ICommand KitchenightOff = new LightsOffCommand(kitchenLight); ICommand garageDoorOpen = new GarageOpenCommand(garage); ICommand garageDoorClose = new GarageCloseCommand(garage); ICommand stereoWithCd = new StereoWithCDCommand(stereo); ICommand stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, livigRommLightOn, livigRommLightOff); remote.SetCommand(1, KitchenLightOn, KitchenightOff); remote.SetCommand(2, garageDoorOpen, garageDoorClose); remote.SetCommand(3, stereoWithCd, stereoOff); remote.DisplayButtons(); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(2); remote.OnButtonWasPushed(3); remote.OffButtonWasPushed(3); }
static void TryRemoteControlWithUndoing() { Console.WriteLine("\n----- Remote control with Undo -----\n"); var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living room"); var livingRoomLightOn = new LightsOnCommand(livingRoomLight); var livingRoomLightOff = new LightsOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.PressOnButton(0); remoteControl.PressOffButton(0); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); Console.WriteLine(); remoteControl.PressOffButton(0); remoteControl.PressOnButton(0); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); }