static void Main() { var remote = new SimpleRemoteControl(); var light = new Light(); var garageDoor = new GarageDoor(); var ceilingFan = new CeilingFan(); var lightOn = new LightOnCommand(light); var lightOff = new LightOffCommand(light); var garageDoorOpen = new GarageDoorOpenCommand(garageDoor); var garageDoorClose = new GarageDoorCloseCommand(garageDoor); var ceilingFanTurnOn = new CeilingFanTurnOnHighCommand(ceilingFan); var ceilingFanTurnOff = new CeilingFanTurnOffCommand(ceilingFan); remote.SetCommand(0, lightOn, lightOff); remote.SetCommand(1, garageDoorOpen, garageDoorClose); remote.SetCommand(2, ceilingFanTurnOn, ceilingFanTurnOff); Console.WriteLine(remote); remote.OnButtonWasPressed(0); remote.OffButtonWasPressed(0); remote.OnButtonWasPressed(1); remote.OffButtonWasPressed(1); remote.OnButtonWasPressed(2); //remote.OffButtonWasPressed(2); remote.UndoButtonWasPressed(); //remote.UndoButtonWasPressed(); //remote.UndoButtonWasPressed(); Console.ReadKey(); }
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); }