Example #1
0
        static void Main(string[] args)
        {
            RemoteControl remote = new RemoteControl();
            Light         light  = new Light();
            GarageDoor    door   = new GarageDoor();
            Stereo        stereo = new Stereo();

            Command lightOn  = new LightOnCommand(light);
            Command lightOff = new LightOffCommand(light);

            Command doorOpen  = new GarageDoorOpenCommand(door);
            Command doorClose = new GarageDoorCloseCommand(door);

            Command stereoOn  = new StereoOnWithCDCommand(stereo);
            Command stereoOff = new StereoOffWithCDCommand(stereo);

            remote.SetCommand(0, lightOn, lightOff);
            remote.SetCommand(1, doorOpen, doorClose);
            remote.SetCommand(2, stereoOn, stereoOff);

            Console.WriteLine(remote);

            remote.OnButtonWasPush(0);
            remote.OffButtonWasPush(0);
            Console.WriteLine(remote);

            remote.UndoButtonWasPush();

            remote.OnButtonWasPush(1);
            remote.OffButtonWasPush(1);
            Console.WriteLine(remote);

            remote.UndoButtonWasPush();
            remote.OnButtonWasPush(2);
            remote.OffButtonWasPush(2);

            Console.ReadKey();
        }
 public GarageDoorOpenCommand(GarageDoor door)
 {
     this.door = door;
 }
 public GarageDoorCloseCommand(GarageDoor door)
 {
     this.door = door;
 }