public GardenLightStandardTimeCommand(GardenLight gardenLight) { _gardenLight = gardenLight; }
public GardenLightSummerTimeCommand(GardenLight gardenLight) { _gardenLight = gardenLight; }
public GardenLightOffCommand(GardenLight gardenLight) { _gardenLight = gardenLight; }
/// <summary> /// O padrão Command encapsula uma solicitação como um objeto, o que lhe permite parametrizar outros objetos com diferentes solicitações, /// enfileirar ou registrar solicitações e implementar recursos de cancelamento de operações. /// </summary> private static void TestCommand() { RemoteControl remoteControl = new RemoteControl(); Light kitchenLight = new Light("Kitchen"); Light livingRoomLight = new Light("Living Room"); TV livingRoomTV = new TV("Living Room"); CeilingFan livingRoomFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo(); GardenLight gardenLight = new GardenLight(); remoteControl.onCommands[0] = new LightOnCommand(kitchenLight); remoteControl.offCommands[0] = new LightOffCommand(kitchenLight); remoteControl.onCommands[1] = new LightOnCommand(livingRoomLight); remoteControl.offCommands[1] = new LightOffCommand(livingRoomLight); remoteControl.onCommands[2] = new GardenLightOnCommand(gardenLight); remoteControl.offCommands[2] = new GardenLightOffCommand(gardenLight); remoteControl.onCommands[3] = new CeilingFanOnCommand(livingRoomFan); remoteControl.offCommands[3] = new CeilingFanOffCommand(livingRoomFan); remoteControl.onCommands[4] = new StereoOnCommand(stereo); remoteControl.offCommands[4] = new StereoOffCommand(stereo); remoteControl.onCommands[5] = new MacroCommand(new ICommand[] { new TVOnCommand(livingRoomTV), new StereoOnCommand(stereo), new CeilingFanOnCommand(livingRoomFan), new LightOffCommand(livingRoomLight) } ); remoteControl.offCommands[5] = new MacroCommand(new ICommand[] { new TVOffCommand(livingRoomTV), new StereoOffCommand(stereo), new CeilingFanOffCommand(livingRoomFan), new LightOnCommand(livingRoomLight) } ); remoteControl.ExecuteOnCommand(2); Console.WriteLine("-----------------------"); remoteControl.ExecuteOffCommand(2); Console.WriteLine("-----------------------"); remoteControl.ExecuteOnCommand(0); Console.WriteLine("-----------------------"); remoteControl.ExecuteOnCommand(6); Console.WriteLine("-----------------------"); remoteControl.ExecuteOffCommand(0); Console.WriteLine("-----------------------"); remoteControl.ExecuteOnCommand(5); Console.WriteLine("-----------------------"); remoteControl.UndoCommand(); Console.WriteLine("-----------------------"); remoteControl.UndoCommand(); Console.WriteLine("-----------------------"); remoteControl.onCommands[2] = new GardenLightSummerTimeCommand(gardenLight); remoteControl.offCommands[2] = new GardenLightStandardTimeCommand(gardenLight); remoteControl.ExecuteOnCommand(2); Console.WriteLine("-----------------------"); remoteControl.ExecuteOffCommand(2); Console.WriteLine("-----------------------"); }