static void TryRemoteControlWithUndoingForCeilingFan() { Console.WriteLine("\n----- Remote control with Undo for ceiling fan -----\n"); var remoteControl = new RemoteControl(); var ceilingFan = new CeilingFan("Living room"); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); remoteControl.PressOnButton(0); remoteControl.PressOffButton(0); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); Console.WriteLine(); remoteControl.PressOnButton(1); Console.WriteLine(remoteControl); remoteControl.PressUndoButton(); }
public static void Start() { var remoteControl = new RemoteControl(); var light = new Light(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var stereo = new Stereo(); var stereoOn = new StereoOnCommand(stereo); var stereoOff = new StereoOffCommand(stereo); var ceililngFan = new CeilingFan("Kitchen room"); var ceililngFanLowOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Low); var ceililngFanMediumOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.Medium); var ceililngFanHighOn = new CeilingFanOnCommand(ceililngFan, CeilingFanSpeed.High); var ceililngFanOff = new CeilingFanOffCommand(ceililngFan); var partyOn = new MacroCommand(new ICommand[] { lightOn, stereoOn }); var partyOff = new MacroCommand(new ICommand[] { lightOff, stereoOff }); remoteControl.SetCommand(2, lightOn, lightOff); remoteControl.SetCommand(3, stereoOn, stereoOff); remoteControl.SetCommand(4, ceililngFanLowOn, ceililngFanOff); remoteControl.SetCommand(5, ceililngFanMediumOn, ceililngFanOff); remoteControl.SetCommand(6, ceililngFanHighOn, ceililngFanOff); remoteControl.SetCommand(1, partyOn, partyOff); remoteControl.P(); RemoteControlPressButtons(remoteControl); }
static void Main(string[] args) { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light(false, "Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room", CeilingFan.Off); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan); CeilingFanLowCommand ceilingFanLowCommand = new CeilingFanLowCommand(livingRoomCeilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.SetCommand(2, ceilingFanLowCommand, ceilingFanOffCommand); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); }
public void Load() { RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); Light light = new Light(); TV tv = new TV(); Hottub hottub = new Hottub(); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCd = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); LightOnCommand lightOn = new LightOnCommand(light); StereoOnCommand stereoOn = new StereoOnCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); LightOffCommand lightOff = new LightOffCommand(light); TVOffCommand tvOff = new TVOffCommand(tv); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; Command[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(4, stereoOnWithCd, stereoOff); remoteControl.SetCommand(5, garageDoorUp, garageDoorDown); remoteControl.SetCommand(6, partyOnMacro, partyOffMacro); Console.WriteLine(remoteControl); for (int i = 0; i <= 6; i++) { remoteControl.OnButtonWasPushed(i); remoteControl.OffButtonWasPushed(i); remoteControl.UndoButtonWasPushed(); } }
public static void Main(string[] args) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Chapter6 - Command"); Console.WriteLine(); SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remote.SetCommand(lightOn); remote.ButtonWasPressed(); RemoteControl rc = new RemoteControl(); Console.WriteLine(rc.ToString()); Light lightInBedroom = new Light(); LightOnCommand lightInBedroom_OnCommand = new LightOnCommand(lightInBedroom); LightOffCommand lightInBedroom_OffCommand = new LightOffCommand(lightInBedroom); Stereo myStereo = new Stereo(); StereoOnWithCDCommand myStereo_On = new StereoOnWithCDCommand(myStereo); StereoOffWithCDCommand myStereo_Off = new StereoOffWithCDCommand(myStereo); CeilingFan fan = new CeilingFan("Living room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(fan); MacroCommand macroCommand_On = new MacroCommand(new ICommand[] { lightInBedroom_OnCommand, myStereo_On, ceilingFanHighCommand }); MacroCommand macroCommand_Off = new MacroCommand(new ICommand[] { lightInBedroom_OffCommand, myStereo_Off, ceilingFanOffCommand }); rc.SetCommand(0, lightInBedroom_OnCommand, lightInBedroom_OffCommand); rc.SetCommand(1, myStereo_On, myStereo_Off); rc.SetCommand(2, ceilingFanHighCommand, ceilingFanOffCommand); rc.SetCommand(6, macroCommand_On, macroCommand_Off); Console.WriteLine(rc.ToString()); rc.OnButtonWasPressed(0); rc.OnButtonWasPressed(1); rc.OffButtonWasPressed(0); rc.UndoButtonWasPressed(); rc.OnButtonWasPressed(2); rc.UndoButtonWasPressed(); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Call macro command"); rc.OnButtonWasPressed(6); rc.OffButtonWasPressed(6); Console.WriteLine(); Console.WriteLine("-----------------------------"); Console.WriteLine("Macro command finished"); Console.WriteLine(); Console.WriteLine(rc.ToString()); Console.ReadKey(); }
public static void Run() { var remoteControl = new RemoteControlWithUndo(); var livingRoomLight = new Light("Living Room"); var ceilingFan = new CeilingFan("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.UndoButtonWasPushed(2); Console.WriteLine(); }
static void Main(string[] args) { var remoteControl = new RemoteControl(); //var livingRoomLight = new Light("Living room"); //var kitchenLight = new Light("Kithen"); var ceilingFan = new CeilingFan("Living room"); //var garageDoor = new GarageDoor(""); //var stereo = new Stereo("Living room"); //var livingRoomLightOn = new LightOnCommand(livingRoomLight); //var livingRoomLightOff = new LightOffCommand(livingRoomLight); //var kitchenLightOn = new LightOnCommand(kitchenLight); //var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanMediumCommand = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHighCommand = new CeilingFanHighCommand(ceilingFan); var ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); //var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); //var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); //var garageDoorUp = new GarageDoorUpCommand(garageDoor); //var garageDoorDown = new GarageDoorDownCommand(garageDoor); //var stereoOnWithCd = new StereoOnWithCdCommand(stereo); //var stereoOff = new StereoOffCommand(stereo); // we are going to fill all these commands into remote control //remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanMediumCommand, ceilingFanOffCommand); remoteControl.SetCommand(3, ceilingFanHighCommand, ceilingFanOffCommand); //remoteControl.SetCommand(3, garageDoorUp, garageDoorDown); // print our remote control //System.Console.WriteLine(remoteControl); // pushing the buttons!!! remoteControl.OnButtonPressed(2); remoteControl.OffButtonPressed(2); System.Console.WriteLine(remoteControl); remoteControl.UndoButtonPressed(); remoteControl.OnButtonPressed(3); System.Console.WriteLine(remoteControl); remoteControl.UndoButtonPressed(); System.Console.ReadKey(); }
public static void Run() { var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living Room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living Room"); var garageDoor = new GarageDoor(""); var stereo = new Stereo("Living Room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorUp = new GarageDoorUpCommand(garageDoor); var garageDoorDown = new GarageDoorDownCommand(garageDoor); var stereoOnWithCD = new StereoOnWithCDCommand(stereo); var stereoOff = new StereoOffCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl); Console.WriteLine(); remoteControl.OnButtonWasPushed(0); Console.WriteLine(); remoteControl.OffButtonWasPushed(0); Console.WriteLine(); remoteControl.OnButtonWasPushed(1); Console.WriteLine(); remoteControl.OffButtonWasPushed(1); Console.WriteLine(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(); remoteControl.OffButtonWasPushed(2); Console.WriteLine(); remoteControl.OnButtonWasPushed(3); Console.WriteLine(); remoteControl.OffButtonWasPushed(3); }
private static string ProcessRemoteControl() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garage = new GarageDoor(); Stereo stereo = new Stereo(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOnCommand = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garage); GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garage); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remoteControl.OnCommands[0] = livingRoomLightOn; remoteControl.OnCommands[1] = kitchenLightOn; remoteControl.OnCommands[2] = ceilingFanOnCommand; remoteControl.OnCommands[3] = stereoOnWithCDCommand; remoteControl.OffCommands[0] = livingRoomLightOff; remoteControl.OffCommands[1] = kitchenLightOff; remoteControl.OffCommands[2] = ceilingFanOffCommand; remoteControl.OffCommands[3] = stereoOffCommand; StringBuilder sb = new StringBuilder(); sb.AppendLine(remoteControl.ToString()); sb.AppendLine(remoteControl.OnButtonWasPushed(0)); sb.AppendLine(remoteControl.OffButtonWasPushed(0)); sb.AppendLine(remoteControl.OnButtonWasPushed(1)); sb.AppendLine(remoteControl.OffButtonWasPushed(1)); sb.AppendLine(remoteControl.OnButtonWasPushed(2)); sb.AppendLine(remoteControl.OffButtonWasPushed(2)); sb.AppendLine(remoteControl.OnButtonWasPushed(3)); sb.AppendLine(remoteControl.OffButtonWasPushed(3)); return(sb.ToString()); }
public void CommandExample() { RemoteControl remote = new RemoteControl(); // this is the invoker Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen Room"); GarageDoor garageDoor = new GarageDoor(""); CeilingFan ceilingFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnHighCommand ceilingFanOnHigh = new CeilingFanOnHighCommand(ceilingFan); CeilingFanOnMediumCommand ceilingFanOnMedium = new CeilingFanOnMediumCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, kitchenLightOn, kitchenLightOff); remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOnMedium); remote.SetCommand(3, stereoOnWithCd, stereoOff); Console.WriteLine(remote); remote.OnButtonWasPushed(0); remote.OffButtonWasPushed(0); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(1); remote.OffButtonWasPushed(1); remote.OnButtonWasPushed(2); remote.OffButtonWasPushed(2); remote.UndoButtonWasPushed(); remote.OnButtonWasPushed(3); remote.OffButtonWasPushed(3); remote.UndoButtonWasPushed(); Console.ReadLine(); }
public static void Run() { // Invoker RemoteControl remoteControl = new RemoteControl(); // Receivers Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); // Commands LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); CeilingFanOnLowCommand ceilingFanOnLow = new CeilingFanOnLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor); // Set Commands remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, stereoOnWithCD, stereoOff); remoteControl.SetCommand(3, ceilingFanOnLow, ceilingFanOff); remoteControl.SetCommand(4, garageDoorUp, garageDoorDown); Console.WriteLine(remoteControl); // Invoke Commands for (int i = 0; i < remoteControl.numberOfSlots; i++) { remoteControl.OnButtonWasPushed(i); remoteControl.OffButtonWasPushed(i); } }
static void Main(string[] args) { int numberOfSlots = 7; // create command invoker: RemoteControl remoteControl = new RemoteControl(numberOfSlots); // create command receivers: Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("LivingRoom"); // create living room light commands: LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); // feed invoker with living room light commands: remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); // create living room ceiling fan commands: CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); // feed invoker with living room ceiling fan commands: remoteControl.SetCommand(1, ceilingFanHigh, ceilingFanOff); // feed invoker with kitchen light commands (using lambdas): remoteControl.SetCommand(2, new Command(() => kitchenLight.On(), () => kitchenLight.Off()), new Command(() => kitchenLight.Off(), () => kitchenLight.On())); // show command settings: WriteLine(remoteControl); // simulate user behaviour: remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); // keep console open: ReadLine(); } // Main
public void RemoteControl_ToString() { RemoteControl control = new RemoteControl(); GarageDoor door = new GarageDoor(); Light light = new Light(); CeilingFan fan = new CeilingFan(); GarageDoorOpenCommand openGarageCommand = new GarageDoorOpenCommand(door); GarageDoorCloseCommand closeGarageCommand = new GarageDoorCloseCommand(door); LightOffCommand lightOffCommand = new LightOffCommand(light); LightOnCommand lightOnCommand = new LightOnCommand(light); CeilingFanHighCommand fanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand fanOffCommand = new CeilingFanOffCommand(fan); control.SetCommand(0, lightOnCommand, lightOffCommand); control.SetCommand(1, openGarageCommand, closeGarageCommand); control.SetCommand(2, fanHighCommand, fanOffCommand); Console.WriteLine(control.ToString()); }
static void Main(string[] args) { RemoteControl Remote = new RemoteControl(); Light Light = new Light(); LightOnCommand LightOn = new LightOnCommand(Light); LightOffCommand LightOff = new LightOffCommand(Light); CeilingFan Fan = new CeilingFan("Living room"); CeilingFanHighCommand FanHigh = new CeilingFanHighCommand(Fan); CeilingFanLowCommand FanLow = new CeilingFanLowCommand(Fan); CeilingFanMediumCommand FanMedium = new CeilingFanMediumCommand(Fan); CeilingFanOffCommand FanOff = new CeilingFanOffCommand(Fan); GarageDoor GarageDoor = new GarageDoor(); GarageCloseDoorCommand GarageCloseDoor = new GarageCloseDoorCommand(GarageDoor); GarageOpenDoorCommand GarageOpenDoor = new GarageOpenDoorCommand(GarageDoor); ICommand[] OnCommands = { LightOn, FanHigh, GarageOpenDoor }; ICommand[] OffCommands = { LightOff, FanOff, GarageCloseDoor }; MacroCommand MacroOnCommand = new MacroCommand(OnCommands); MacroCommand MacroOffCommand = new MacroCommand(OffCommands); Remote.SetCommand(0, LightOn, LightOff); Remote.SetCommand(1, FanMedium, FanOff); Remote.SetCommand(2, FanHigh, FanOff); Remote.SetCommand(3, MacroOnCommand, MacroOnCommand); Console.WriteLine(Remote.ToString()); Remote.OnButtonPressed(3); Remote.UndoButtonWasPressed(); //Remote.OnButtonPressed(0); //Remote.UndoButtonWasPressed(); //Remote.OnButtonPressed(1); //Remote.OffButtonPressed(1); //Console.WriteLine(Remote.ToString()); //Remote.UndoButtonWasPressed(); //Remote.OnButtonPressed(2); //Console.WriteLine(Remote.ToString()); //Remote.UndoButtonWasPressed(); }
public void MacroCommandTestMethod() { Light livingRoomLight = new Light("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); ICommand[] study = { livingRoomLightOn, ceilingFanHighCommand }; ICommand[] stopStudy = { livingRoomLightOn, ceilingFanHighCommand }; MacroCommand studyMacro = new MacroCommand(study); MacroCommand stopStudyMacro = new MacroCommand(stopStudy); RemoteControl remoteControl = new RemoteControl(totalSlots: 1); remoteControl.SetCommand(0, studyMacro, stopStudyMacro); remoteControl.OnButtonWasPushed(0); }
public void SimpleCommandPatternTestMethod() { RemoteControl remoteControl = new RemoteControl(totalSlots: 7); Light livingRoomLight = new Light("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); CeilingFan livingRoomCeilingFan = new CeilingFan("Living Room"); CeilingFanHighCommand ceilingFanHighCommand = new CeilingFanHighCommand(livingRoomCeilingFan); CeilingFanOffCommand ceilingFanOffCommand = new CeilingFanOffCommand(livingRoomCeilingFan); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, ceilingFanHighCommand, ceilingFanOffCommand); remoteControl.OnButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(0); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPressed(); }
public void RemoteControl_Undo() { RemoteControl control = new RemoteControl(); GarageDoor door = new GarageDoor(); Light light = new Light(); CeilingFan fan = new CeilingFan(); GarageDoorOpenCommand openGarageCommand = new GarageDoorOpenCommand(door); GarageDoorCloseCommand closeGarageCommand = new GarageDoorCloseCommand(door); LightOffCommand lightOffCommand = new LightOffCommand(light); LightOnCommand lightOnCommand = new LightOnCommand(light); CeilingFanHighCommand fanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand fanOffCommand = new CeilingFanOffCommand(fan); control.SetCommand(0, lightOnCommand, lightOffCommand); control.SetCommand(1, openGarageCommand, closeGarageCommand); control.SetCommand(2, fanHighCommand, fanOffCommand); control.ClickButtonOn(0); control.ClickButtonOn(1); control.ClickButtonOff(2); control.UndoButtonClick(); }
public static void CeilingFanTest() { var remoteControl = new RemoteControl(); var ceilingFan = new CeilingFan("Living Room"); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); var ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); remoteControl.SetCommand(1, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(2, ceilingFanHigh, ceilingFanOff); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); Console.WriteLine(remoteControl); remoteControl.UndoButtonWasPushed(); Console.ReadKey(); }
public static void CommandExample() { Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); RemoteControl remoteControl = new RemoteControl(); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); Console.WriteLine(remoteControl.ToString()); remoteControl.OnButtonPushed(0); remoteControl.OffButtonPushed(0); remoteControl.OnButtonPushed(1); remoteControl.OffButtonPushed(1); remoteControl.OnButtonPushed(2); remoteControl.OffButtonPushed(2); remoteControl.OnButtonPushed(3); remoteControl.OffButtonPushed(3); }
public void RemoteControl_Macro() { RemoteControl control = new RemoteControl(); GarageDoor door = new GarageDoor(); Light light = new Light(); CeilingFan fan = new CeilingFan(); GarageDoorOpenCommand openGarageCommand = new GarageDoorOpenCommand(door); GarageDoorCloseCommand closeGarageCommand = new GarageDoorCloseCommand(door); LightOffCommand lightOffCommand = new LightOffCommand(light); LightOnCommand lightOnCommand = new LightOnCommand(light); CeilingFanHighCommand fanHighCommand = new CeilingFanHighCommand(fan); CeilingFanOffCommand fanOffCommand = new CeilingFanOffCommand(fan); List <ICommand> onCommands = new List <ICommand>() { new GarageDoorOpenCommand(door), new LightOnCommand(light), new CeilingFanHighCommand(fan) }; List <ICommand> offCommands = new List <ICommand>() { new GarageDoorCloseCommand(door), new LightOffCommand(light), new CeilingFanOffCommand(fan) }; MacroCommand onMacro = new MacroCommand(onCommands); MacroCommand offMacro = new MacroCommand(offCommands); control.SetCommand(0, onMacro, offMacro); control.ClickButtonOn(0); control.ClickButtonOff(0); control.UndoButtonClick(); }
static void Main(string[] args) { Console.WriteLine("SIMPLE REMOTE CONTROL"); var simpleRemoteControl = new SimpleRemoteControl(); var light = new Light("Living room"); var lightOn = new LightOnCommand(light); simpleRemoteControl.SetCommand(lightOn); simpleRemoteControl.ButtonWasPressed(); var garageDoorSimpleControl = new GarageDoor(); var garageOpen = new GarageDoorOpenCommand(garageDoorSimpleControl); simpleRemoteControl.SetCommand(garageOpen); simpleRemoteControl.ButtonWasPressed(); Console.WriteLine("REMOTE CONTROL"); var remoteControl = new RemoteControl(); var livingRoomLight = new Light("Living room"); var kitchenLight = new Light("Kitchen"); var ceilingFan = new CeilingFan("Living room"); var garageDoor = new GarageDoor(); var stereo = new Stereo("Living room"); var livingRoomLightOn = new LightOnCommand(livingRoomLight); var livingRoomLightOff = new LightOffCommand(livingRoomLight); var kitchenLightOn = new LightOnCommand(kitchenLight); var kitchenLightOff = new LightOffCommand(kitchenLight); var ceilingFanOn = new CeilingFanOnCommand(ceilingFan); var ceilingFanOff = new CeilingFanOffCommand(ceilingFan); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var stereoOnWithCd = new StereoOnWithCdCommand(stereo); var stereoOffWithCd = new StereoOffWithCdCommand(stereo); remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.SetCommand(3, stereoOnWithCd, stereoOffWithCd); Console.WriteLine(remoteControl.ToString()); Console.WriteLine("-----------------FUNÇÕES EXECUTANDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO"); remoteControl.OnButtonWasPushed(0); remoteControl.OffButtonWasPushed(0); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(1); remoteControl.OffButtonWasPushed(1); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(2); remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("REMOTE CONTROL WITH UNDO OF THE CEILING FAN"); var remoteControlCeilingFan = new RemoteControl(); var ceilingFanHigh = new CeilingFanHightCommand(ceilingFan); var ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); remoteControlCeilingFan.SetCommand(0, ceilingFanMedium, ceilingFanOff); remoteControlCeilingFan.SetCommand(1, ceilingFanHigh, ceilingFanOff); remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OffButtonWasPushed(0); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); //remoteControlCeilingFan.OnButtonWasPushed(0); remoteControlCeilingFan.OnButtonWasPushed(1); Console.WriteLine(remoteControlCeilingFan.ToString()); remoteControlCeilingFan.UndoButtonWasPushed(); Console.WriteLine(""); Console.WriteLine("MACRO COMAND (PARTY MODE)"); var tv = new Tv("Living room"); var hottub = new Hottub(); var tvOn = new TvOnCommand(tv); var tvOff = new TvOffCommand(tv); var hottubOn = new HottubOnCommand(hottub); var hottubOff = new HottubOffCommand(hottub); var commandsPartyOn = new List <ICommand>() { livingRoomLightOn, stereoOnWithCd, tvOn, hottubOn }; var commandsPartyOff = new List <ICommand>() { livingRoomLightOff, stereoOffWithCd, tvOff, hottubOff }; var partyOn = new MacroCommand(commandsPartyOn); var partyOff = new MacroCommand(commandsPartyOff); var remoteControlParty = new RemoteControl(); remoteControlParty.SetCommand(0, partyOn, partyOff); Console.WriteLine(remoteControlParty.ToString()); Console.WriteLine("PUSHING MACRO ON"); remoteControlParty.OnButtonWasPushed(0); Console.WriteLine("PUSHING MACRO OFF"); remoteControlParty.OffButtonWasPushed(0); Console.ReadKey(); }
public static void Run() { // Invoker RemoteControlWithUndo remoteControl = new RemoteControlWithUndo(); // Receivers Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); // Commands LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorUp = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageDoorDown = new GarageDoorCloseCommand(garageDoor); // Set Commands remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.SetCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.SetCommand(2, ceilingFanLow, ceilingFanOff); remoteControl.SetCommand(3, ceilingFanMedium, ceilingFanOff); remoteControl.SetCommand(4, ceilingFanHigh, ceilingFanOff); remoteControl.SetCommand(5, garageDoorUp, garageDoorDown); remoteControl.SetCommand(6, stereoOnWithCD, stereoOff); // Invoke Commands Console.WriteLine("=================================================="); Console.WriteLine("============= Testing Remote Loader ============="); Console.WriteLine("=================================================="); Console.WriteLine(); Console.WriteLine(remoteControl); Console.WriteLine(); for (int i = 0; i < remoteControl.numberOfSlots; i++) { remoteControl.OnButtonWasPushed(i); remoteControl.OffButtonWasPushed(i); if (!(remoteControl.onCommands[i] is NoCommand)) { Console.WriteLine(); } } Console.WriteLine(); Console.WriteLine("----- Undo -----"); remoteControl.UndoButtonWasPushed(); }
public void TestTurningOn()//Command Pattern Client { //Command Pattern Invoker Remote remote = new Remote(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor(""); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); remote.SetCommand(1, kitchenLightOn, kitchenLightOff); remote.SetCommand(2, ceilingFanOn, ceilingFanOff); remote.SetCommand(3, stereoOnWithCD, stereoOff); Assert.AreEqual("Living Room light is on", remote.OnButtonWasPushed(0)); Assert.AreEqual("Living Room light is off", remote.OffButtonWasPushed(0)); Assert.AreEqual("Kitchen light is on", remote.OnButtonWasPushed(1)); Assert.AreEqual("Kitchen light is off", remote.OffButtonWasPushed(1)); Assert.AreEqual("Living Room ceiling fan is on high", remote.OnButtonWasPushed(2)); Assert.AreEqual("Living Room ceiling fan is off", remote.OffButtonWasPushed(2)); Assert.AreEqual("Living Room stereo is on\n" + "Living Room stereo is set for CD input\n" + "Living Room Stereo volume set to 11", remote.OnButtonWasPushed(3)); Assert.AreEqual("Living Room stereo is off", remote.OffButtonWasPushed(3)); // Console.WriteLine(remote.toString()); }
/* Esta clase contiene toda la lógica de nuestro patrón comando, * analicémosla detenidamente */ public static RemoteControl CreateControl() { /* Nuestro control es nuestro invocador, es el que da comandos y * los demás los ejecutan, veámoslo un poco más de cerca * entra a la clase RemoteControl Para analizarla */ RemoteControl control = new RemoteControl(); /* Como pudiste ver el control no tiene ningún conocimiento de como * se realizan los comandos, lo único que hace es llamarlos y ejecutarlos, * * el siguiente proceso crea a los recibidores o accionadores que son los * que se encargan de ejecutar y hacer realidad nuestros comandos * * entra en las clases para analizarlas */ ILight livingRoomLight = new LivingRoomLight(); CeilingFan ceilingFan = new CeilingFan(); ILight kitchenLight = new KitchenLight(); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo(); ILight allLights = new AllLights(); HotTub hotTub = new HotTub(); TV tv = new TV(); /* Como pudiste observar cada uno de estos receptores define como * ejecutar sus acciones; acontinuacionel en siguiente proceso podrás * observar cómo se crean los comandos para ser almacenados dentro de nuestro * control que funcionara como nuestro invocador. */ //Este proceso crea los comandos, recibiendo como parametro //la clase que ejecutara el proceso(receptor) //Entra a LightsOnCommands para analizarlo LightsOnCommands livingRoomLightsOn = new LightsOnCommands(livingRoomLight); LightsOffCommands livingRoomLightsOff = new LightsOffCommands(livingRoomLight); LightsOnCommands kitchenLightsOn = new LightsOnCommands(kitchenLight); LightsOffCommands kitchenLightsOff = new LightsOffCommands(kitchenLight); LightsOnCommands allLightsOn = new LightsOnCommands(allLights); LightsOffCommands allLightsOff = new LightsOffCommands(allLights); CeilingFanLowCommand ceilingFanOn = new CeilingFanLowCommand(ceilingFan); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanHightCommand ceilingFanHight = new CeilingFanHightCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageDoorClose = new GarageDoorCloseCommand(garageDoor); StereoWithCDOnCommand stereoWithCDOn = new StereoWithCDOnCommand(stereo); StereoWithCDOffCommand stereoWithCDOff = new StereoWithCDOffCommand(stereo); HotTubOnCommand hotTubOn = new HotTubOnCommand(hotTub); HotTubOffCommand hotTubOff = new HotTubOffCommand(hotTub); TvOffCommand tvOff = new TvOffCommand(tv); TvOnCommand tvOn = new TvOnCommand(tv); /* para el modo fiesta necesitaremos un comando especial, que pueda recibir una * serie de comandos y los ejecute, por eso fue creada la clase MacroCommand que * ejecuta una serie de comandos. */ ICommand[] PartyModeCommandsOn = { livingRoomLightsOn, stereoWithCDOn, tvOn, hotTubOn }; ICommand[] PartyModeCommandsOff = { livingRoomLightsOff, stereoWithCDOff, tvOff, hotTubOff }; MacroCommand PartyModeOn = new MacroCommand(PartyModeCommandsOn); MacroCommand PartyModeOff = new MacroCommand(PartyModeCommandsOff); //Al almacenar los comandos en el control habilitamos la funcionalidad //para que sea ejecutada al presionar algún boton, ve a la clase principal //del proyecto y ve cómo se ejecuta cada una de las acciones control.OnCommands[0] = livingRoomLightsOn; control.OffCommands[0] = livingRoomLightsOff; control.OnCommands[1] = kitchenLightsOn; control.OffCommands[1] = kitchenLightsOff; control.OnCommands[2] = allLightsOn; control.OffCommands[2] = allLightsOff; control.OnCommands[3] = ceilingFanOn; control.OffCommands[3] = ceilingFanOff; control.OnCommands[4] = ceilingFanMedium; control.OffCommands[4] = ceilingFanOff; control.OnCommands[5] = ceilingFanHight; control.OffCommands[5] = ceilingFanOff; control.OnCommands[6] = garageDoorOpen; control.OffCommands[6] = garageDoorClose; control.OnCommands[7] = stereoWithCDOn; control.OffCommands[7] = stereoWithCDOff; control.OnCommands[8] = PartyModeOn; control.OffCommands[8] = PartyModeOff; control.OnCommands[9] = new NoCommand(); control.OffCommands[9] = new NoCommand(); return(control); }
static void Main(string[] args) { #region Strategy Pattern //Duck mallardDuck = new MallardDuck(); //mallardDuck.PerformQuack(); //mallardDuck.PerformFly(); //Duck modelDuck = new ModeldDuck(); //modelDuck.PerformFly(); //modelDuck.PerformQuack(); //modelDuck.setFlyBhavior(new FlyRocketPowered());// to change behavior at runtime just call setter method //modelDuck.PerformFly(); //mallardDuck.Display(); #endregion #region Observer Pattern //WeatherData weatherData = new WeatherData(); //CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData); //weatherData.SetMeaserments(32.46f, 65, 30.4f); #endregion #region Decorator Pattern //Beverage beverage = new Espresso(); //Console.WriteLine(beverage.GetDiscription() + " TK-" + beverage.cost()); //Console.ReadLine(); #endregion #region Factory Pattern //PizzaStore nyPizzaStore = new NYPizzaStore(); //ProductPizza pizza = nyPizzaStore.Orderpizza("Cheese"); #endregion #region Command Pattern RemoteControl remoteControl = new RemoteControl();// invoker, it will be passed a command object that can be used to make request #region #region Create all devices in their Proper Location Light livingRoomLight = new Light("Living Room");// receiver of the request Light kitchenRoomLight = new Light("kitchen Room"); CeilingFan ceilingFan = new CeilingFan("Living Room"); Stereo stereo = new Stereo("Living Room"); GarageDoor garageDoor = new GarageDoor(); #endregion #region Create all the command object LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); // create a command & pass it to the receiver LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); // create a command & pass it to the receiver LightOnCommand KichenRoomLightOn = new LightOnCommand(kitchenRoomLight); // create a command & pass it to the receiver LightOffCommand KichenRoomLightOff = new LightOffCommand(kitchenRoomLight); // create a command & pass it to the receiver CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); StereoOffCommand stereoOff = new StereoOffCommand(stereo); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); GarageDoorOpenCommand garageDoorOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); #endregion #region load all commands in the remote slot //remoteControl.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remoteControl.SetCommand(1, KichenRoomLightOn, KichenRoomLightOff); //remoteControl.SetCommand(2, ceilingFanOn, ceilingFanOff); //remoteControl.SetCommand(3, stereoOnWithCD, stereoOff); #endregion #region action //Console.WriteLine(remoteControl); //remoteControl.OnButtonWasPushed(0); //remoteControl.OffButtonWasPushed(0); //remoteControl.OnButtonWasPushed(1); //remoteControl.OffButtonWasPushed(1); //remoteControl.OnButtonWasPushed(2); //remoteControl.OffButtonWasPushed(2); //remoteControl.OnButtonWasPushed(3); //remoteControl.OffButtonWasPushed(3); #endregion #endregion #region Undo Action in ceiling //CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); //CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); //CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(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(); //Console.WriteLine(remoteControl); #endregion #region Macro Command ICommand[] partyOn = { livingRoomLightOn, stereoOnWithCD, ceilingFanOn, garageDoorOpen }; ICommand[] partyOff = { livingRoomLightOff, stereoOff, ceilingFanOff, garageDoorDown }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remoteControl.SetCommand(0, partyOnMacro, partyOffMacro); //Console.WriteLine(remoteControl); //Console.WriteLine("----Pushing Macro On----"); //remoteControl.OnButtonWasPushed(0); //Console.WriteLine("----Pushing Macro Off----"); //remoteControl.OffButtonWasPushed(0); //Console.WriteLine("----Pushing Macro Undo----"); //remoteControl.undoButtonWasPushed(); #endregion #endregion #region Adapter Pattern //MallaDuck duck = new MallaDuck(); //WildTurkey wildTurkey = new WildTurkey(); //IDuck turkeyAdapter = new TurkeyAdapter(wildTurkey); //Console.WriteLine("The Turkey Says..."); //wildTurkey.Gobble(); //wildTurkey.Fly(); //Console.WriteLine("\n The Duck Says..."); //testDuck(duck); //Console.WriteLine("\n The TurkeyAdapter Says..."); //testDuck(turkeyAdapter); #endregion #region Facade Pattern //Amplifier amp = new Amplifier(); //var tuner = new Tuner(); //DvdPlayer dvdPlayer = new DvdPlayer(); //CdPlayer cdPlayer = new CdPlayer(); //Projector projector = new Projector(); //TheaterLights theaterLights = new TheaterLights(); //Screen screen = new Screen(); //PopcornPopper popper = new PopcornPopper(); //TheaterLights light = new TheaterLights(); //HomeTheaterFacade theaterFacade = new HomeTheaterFacade( tuner, amp, dvdPlayer, cdPlayer, projector, light, screen, popper); //theaterFacade.WatchMovies("BatMan"); //Console.WriteLine("-------------------------"); //theaterFacade.EndMovie(); #endregion #region Template Method Pattern Tea tea = new Tea(); tea.PrepareRecipe(); #endregion #region #endregion #region #endregion #region #endregion #region #endregion Console.ReadLine(); }
static void Main(string[] args) { int numSlots = 5; BetterRemoteControl remote = new BetterRemoteControl(numSlots); Light livingRoomLight = new Light("Living Room"); Light kitchenLght = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor("Downstairs"); Stereo stereo = new Stereo("Living Room"); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(livingRoomLight); LightOffCommand kitchenLightOff = new LightOffCommand(livingRoomLight); CeilingFanHighCommand ceilingFanOnHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanMediumCommand ceilingFanOnMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanOnLow = new CeilingFanLowCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorOpenCommand garageOpen = new GarageDoorOpenCommand(garageDoor); GarageDoorCloseCommand garageClose = new GarageDoorCloseCommand(garageDoor); StereoOnWithCdCommand stereoOnWithCd = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); Command[] partyOn = { livingRoomLightOn, ceilingFanOnHigh, stereoOnWithCd }; Command[] partyOff = { livingRoomLightOff, ceilingFanOff, stereoOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partOffMacro = new MacroCommand(partyOff); Command[] testPartyFanOn = { ceilingFanOnHigh, ceilingFanOnMedium, ceilingFanOnLow }; Command[] testPartyFanOff = { ceilingFanOff }; MacroCommand testPartyFanOnMacro = new MacroCommand(testPartyFanOn); MacroCommand testPartyFanOffMacro = new MacroCommand(testPartyFanOff); //remote.SetCommand(0, livingRoomLightOn, livingRoomLightOff); //remote.SetCommand(1, kitchenLightOn, kitchenLightOff); //remote.SetCommand(2, ceilingFanOnHigh, ceilingFanOff); //remote.SetCommand(3, garageOpen, garageClose); //remote.SetCommand(4, stereoOnWithCd, stereoOff); remote.SetCommand(0, ceilingFanOnHigh, ceilingFanOff); remote.SetCommand(1, ceilingFanOnMedium, ceilingFanOff); remote.SetCommand(2, ceilingFanOnLow, ceilingFanOff); remote.SetCommand(3, partyOnMacro, partOffMacro); remote.SetCommand(4, testPartyFanOnMacro, testPartyFanOffMacro); Console.WriteLine(remote); Console.WriteLine("\n Changing fan settings several times"); remote.OnButtonWasPushed(0); remote.OnButtonWasPushed(1); remote.OnButtonWasPushed(2); Console.WriteLine("\n Undoing fan settings several times"); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); remote.UndoButtonWasPushed(); Console.WriteLine("\nTurning on macro"); remote.OnButtonWasPushed(3); //Console.WriteLine("\nTurning off macro"); //remote.OffButtonWasPushed(3); Console.WriteLine("\nUndoing previous macro button push"); //Though this eventually calls 3 Undo()'s (one for each of the 3 classes in the MacroCommand's Command[]), the stack in //remote control class actually only has 1 object in it, the MacroCommand object remote.UndoButtonWasPushed(); //This won't get called because stack size is not > 0 remote.UndoButtonWasPushed(); Console.WriteLine("\nTesting out how fan's handle the macro class"); remote.OnButtonWasPushed(4); Console.WriteLine("\nUndoing the fan macro class"); remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(1); //remote.UndoButtonWasPushed(); //remote.OnButtonWasPushed(1); //remote.OffButtonWasPushed(1); //remote.OnButtonWasPushed(2); //remote.OffButtonWasPushed(2); //remote.OnButtonWasPushed(3); //remote.OffButtonWasPushed(3); //remote.OnButtonWasPushed(4); //remote.OffButtonWasPushed(4); Console.ReadLine(); }
public static void Test() { RemoteControl remoteControl = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); Light kitchenLight = new Light("Kitchen"); CeilingFan ceilingFan = new CeilingFan("Living Room"); GarageDoor garageDoor = new GarageDoor("Garage"); Stereo stereo = new Stereo("Living Room"); TV tv = new TV("Living Room"); Hottub hottub = new Hottub(); LightOnCommand livingRoomLightOn = new LightOnCommand(livingRoomLight); LightOffCommand livingRoomLightOff = new LightOffCommand(livingRoomLight); LightOnCommand kitchenLightOn = new LightOnCommand(kitchenLight); LightOffCommand kitchenLightOff = new LightOffCommand(kitchenLight); CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor); StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); TVOnCommand tvOn = new TVOnCommand(tv); TVOffCommand tvOff = new TVOffCommand(tv); HottubOnCommand hottubOn = new HottubOnCommand(hottub); HottubOffCommand hottubOff = new HottubOffCommand(hottub); Command[] partyOn = { livingRoomLightOn, stereoOnWithCD, tvOn, hottubOn }; Command[] partyOff = { livingRoomLightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnCommand = new MacroCommand(partyOn); MacroCommand partyOffCommand = new MacroCommand(partyOff); remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff); remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff); remoteControl.setCommand(2, ceilingFanOn, ceilingFanOff); remoteControl.setCommand(3, stereoOnWithCD, stereoOff); remoteControl.setCommand(4, partyOnCommand, partyOffCommand); Console.WriteLine(remoteControl); remoteControl.onButtonWasPushed(0); remoteControl.offButtonWasPushed(0); remoteControl.onButtonWasPushed(1); remoteControl.offButtonWasPushed(1); remoteControl.onButtonWasPushed(2); remoteControl.offButtonWasPushed(2); remoteControl.onButtonWasPushed(3); remoteControl.offButtonWasPushed(3); Console.WriteLine("-------------------------------------------------------------- Party Mode On -----------------------------------------------"); remoteControl.onButtonWasPushed(4); remoteControl.offButtonWasPushed(4); remoteControl.undoButtonPushed(); }