示例#1
0
        static void Main(string[] args)
        {
            RemoteControl remoteControl = 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);
            StereoOnCommand stereoOn = new StereoOnCommand(stereo);
            TVOnCommand     tvOn     = new TVOnCommand(tv);
            HottubOnCommand hottubOn = new HottubOnCommand(hottub);

            LightOffCommand  lightOff  = new LightOffCommand(light);
            StereoOffCommand stereoOff = new StereoOffCommand(stereo);
            TVOffCommand     tvOff     = new TVOffCommand(tv);
            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);

            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.ReadKey();
        }
示例#2
0
 public StereoOnCommand(Stereo stereo)
 {
     this.stereo = stereo;
 }
示例#3
0
 public StereoOnWithCDCommand(Stereo stereo)
 {
     this.stereo = stereo;
 }