public void Run() { RemoteControl rc = new RemoteControl(); Light livingRoomLight = new Light("Living Room"); CeilingFan livingRoomFan = new CeilingFan("Living Room"); Tv livingRoomTv = new Tv("Living Room"); Stereo livingRoomStereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); MacroCommand onCommands = new MacroCommand(new ICommand[] { new LightOnCommand(livingRoomLight), new CeilingFanMediumCommand(livingRoomFan), new TvOnCommand(livingRoomTv), new StereoOnWithCDCommand(livingRoomStereo), new HottubOnCommand(hottub) }); MacroCommand offCommands = new MacroCommand(new ICommand[] { new LightOffCommand(livingRoomLight), new CeilingFanOffCommand(livingRoomFan), new TvOffCommand(livingRoomTv), new StereoOffCommand(livingRoomStereo), new HottubOffCommand(hottub) }); RelayCommand lightOnCommand = new RelayCommand(() => livingRoomLight.On(), () => livingRoomLight.Off()); RelayCommand lightOffCommand = new RelayCommand(() => livingRoomLight.Off(), () => livingRoomLight.On()); rc.SetCommand(0, onCommands, offCommands); rc.OnButtonPushed(0); Console.WriteLine(); rc.OffButtonPushed(0); Console.WriteLine(rc); rc.UndoButtonPushed(); Console.WriteLine(); Console.WriteLine(); rc.SetCommand(1, lightOnCommand, lightOffCommand); Console.WriteLine(rc); rc.OnButtonPushed(1); rc.OffButtonPushed(1); Console.WriteLine(); rc.UndoButtonPushed(); }
static void Main(string[] args) { RemoteControl remote = new RemoteControl(); Light light = new Light("Living Room"); Tv tv = new Tv("Living Room"); Stereo stereo = new Stereo("Living Room"); Hottub hottub = new Hottub(); LightOnCommand lightOn = new LightOnCommand(light); LightOnCommand lightOff = new LightOnCommand(light); TvOnWithDvdCommand tvOn = new TvOnWithDvdCommand(tv); TvOffCommand tvOff = new TvOffCommand(tv); StereoOnWithCdCommand stereoOn = new StereoOnWithCdCommand(stereo); StereoOffCommand stereoOff = new StereoOffCommand(stereo); HottubOnWithBubblesCommand hottubOn = new HottubOnWithBubblesCommand(hottub); HottubOffCommand hottubOff = new HottubOffCommand(hottub); ICommand[] partyOn = { lightOn, stereoOn, tvOn, hottubOn }; ICommand[] partyOff = { lightOff, stereoOff, tvOff, hottubOff }; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); remote.SetCommand(0, partyOnMacro, partyOffMacro); Console.WriteLine(remote); Console.WriteLine("-----Pressing Macro On Button-----"); remote.OnButtonWasPressed(0); Console.WriteLine("-----Pressing Macro Off Button-----"); remote.OffButtonWasPressed(0); }