static void Main(string[] args) { RemoteControl remoteControl = new RemoteControl(); //创建所有的装置 Light kitChenlight = new Light("厨房灯"); Light liveRoomlight = new Light("卧室灯"); Stereo stereo = new Stereo(); //为装置创建命令对象 LightOnCommand kitChenlightOnCommand = new LightOnCommand(kitChenlight); LightOffCommand kitChenlightOffCommand = new LightOffCommand(kitChenlight); LightOnCommand liveRoomlightOnCommand = new LightOnCommand(liveRoomlight); LightOffCommand liveRoomlightOffCommand = new LightOffCommand(liveRoomlight); StereoOnCommand stereoOnCommand = new StereoOnCommand(stereo); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); //将命令对象加载到遥控器中 remoteControl.SetCommand(0, kitChenlightOnCommand, kitChenlightOffCommand); remoteControl.SetCommand(1, liveRoomlightOnCommand, liveRoomlightOffCommand); remoteControl.SetCommand(2, stereoOnCommand, stereoOffCommand); //按下遥控器每个插槽的开关 remoteControl.OnButtonWasPushed(0); remoteControl.OnButtonWasPushed(1); //remoteControl.UndoButtonWasPushed(); remoteControl.OnButtonWasPushed(2); remoteControl.OffButtonWasPushed(0); remoteControl.OffButtonWasPushed(1); remoteControl.OffButtonWasPushed(2); Console.WriteLine("------------------------------"); remoteControl.OnButtonWasPushed(3); remoteControl.OffButtonWasPushed(3); remoteControl.OnButtonWasPushed(4); remoteControl.OffButtonWasPushed(4); }
public StereoOffCommand(Stereo stereo) { this.stereo = stereo; }