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(); } }
static void Main(string[] args) { // Control the light var remote = new RemoteController(); // Invoker var light = new Light(); // Receiver var lightOn = new LightOnCommand(light); // Command var lightOff = new LightOffCommand(light); // Command remote.SetCommand(lightOn); remote.ActivateCommand(); remote.SetCommand(lightOff); remote.ActivateCommand(); // Control the garage door var garageDoor = new GarageDoor(); // Receiver var doorUp = new GarageDoorUpCommand(garageDoor); // Command var doorDown = new GarageDoorDownCommand(garageDoor); // Command // Invoker ---> Command ----> Receiver remote.SetCommand(doorUp); remote.ActivateCommand(); remote.SetCommand(doorDown); remote.ActivateCommand(); Console.ReadKey(); }
public static void Run() { var remote = new SimpleRemoteControl(); var light = new Light(); var garageDoor = new GarageDoor(); var lightOn = new LightOnCommand(light); var garageOpen = new GarageDoorUpCommand(garageDoor); remote.SetCommand(lightOn); remote.ButtonWasPressed(); Console.WriteLine(); remote.SetCommand(garageOpen); remote.ButtonWasPressed(); }
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); }
public void Load() { SimpleRemoteControl remoteControl = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); remoteControl.SetCommand(lightOn); remoteControl.ButtonWasPressed(); GarageDoor garageDoor = new GarageDoor(); GarageDoorUpCommand garageDoorOpenCommand = new GarageDoorUpCommand(garageDoor); remoteControl.SetCommand(garageDoorOpenCommand); remoteControl.ButtonWasPressed(); }
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 void TestTurningSimpleOn()//Command Pattern Client { //Command Pattern Invoker SimpleRemoteControl remote = new SimpleRemoteControl(); //Command Pattern Receivers Light light = new Light("Kitchen"); GarageDoor garageDoor = new GarageDoor(""); //Commands for the receivers LightOnCommand lightOn = new LightOnCommand(light); GarageDoorUpCommand garageDoorOpen = new GarageDoorUpCommand(garageDoor); //Passing the light on command to the invoker remote.SetCommand(lightOn); //Simulate the button being pressed on the invoker Assert.AreEqual("Kitchen light is on", remote.ButtonWasPressed()); //Passing the garage door open command to the invoker remote.SetCommand(garageDoorOpen); //Simulate the button being pressed on the invoker Assert.AreEqual("Garage door is up", remote.ButtonWasPressed()); }
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 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()); }
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(); }
public void Setup() { garageDoor = new GarageDoor(); garageDoorDownCommand = new GarageDoorDownCommand(this.garageDoor); garageDoorUpCommand = new GarageDoorUpCommand(this.garageDoor); }
static void Main(string[] args) // Client { // Example 1 SimpleRemoteControl remote = new SimpleRemoteControl(); // Invoker LightBulb light = new LightBulb(); // Receiver LightOnCommand lightOnCommand = new LightOnCommand(light); // Command remote.SetCommand(lightOnCommand); remote.ButtonWasPressed(); remote.UndoButtonWasPressed(); // Example 2 AdvancedRemote remote2 = new AdvancedRemote(); GarageDoor garageDoor = new GarageDoor(); Stereo stereo = new Stereo(); GarageDoorUpCommand garageDoorUpCommand = new GarageDoorUpCommand(garageDoor); GarageDoorDownCommand garageDoorDownCommand = new GarageDoorDownCommand(garageDoor); StereoOnCommand stereoOnCommand = new StereoOnCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); remote2.SetCommand(0, garageDoorUpCommand, garageDoorDownCommand); remote2.SetCommand(1, stereoOnCommand, stereoOffCommand); remote2.OnButtonWasPressed(0); remote2.OnButtonWasPressed(1); remote2.OffButtonWasPressed(0); remote2.OffButtonWasPressed(1); remote2.UndoButtonWasPressed(); // Example 3 AdvancedRemote remote3 = new AdvancedRemote(); Fan fan = new Fan(); FanHighCommand fanHighCommand = new FanHighCommand(fan); FanMeduimCommand fanMeduimCommand = new FanMeduimCommand(fan); FanLowCommand fanLowCommand = new FanLowCommand(fan); FanOffCommand fanOffCommand = new FanOffCommand(fan); // Remote from Example 2 Reused remote3.SetCommand(0, fanHighCommand, fanOffCommand); remote3.SetCommand(1, fanMeduimCommand, fanOffCommand); remote3.OnButtonWasPressed(0); // High remote3.OffButtonWasPressed(0); // Off remote3.UndoButtonWasPressed(); // Back To High // Example 4 RoomTV roomTV = new RoomTV(); HotTub hotTub = new HotTub(); HotTubOnCommand hotTubOnCommand = new HotTubOnCommand(hotTub); TVOnCommand tvOnCommand = new TVOnCommand(roomTV); Command[] PartyCommands = new Command[2]; PartyCommands[0] = hotTubOnCommand; PartyCommands[1] = tvOnCommand; MacroCommand macroCommand = new MacroCommand(PartyCommands); // Put All Commands in this MacroCommand AdvancedRemote remote4 = new AdvancedRemote(); remote4.SetCommand(0, macroCommand, new NoCommand()); // No Command for Off Button remote4.OnButtonWasPressed(0); }