コード例 #1
0
        /*
         * Reference: YouTube/Derek Banas
         *  Allows you to store lists of code that is executed later time or many times
         * Client says I want a specific  command to run when execute() is called on 1 of these encapsulated objects
         * An object called invoker transfers this command to another object called a receiver to execute the right code
         *
         */
        static void Main(string[] args)
        {
            //setup the devices/receivers
            var lights = new Light();
            var ac     = new AirCondition();

            //setup the concrete commands
            var lightsOn  = new LightOn(lights);
            var lightsOff = new LightOff(lights);
            var acOn      = new AcOn(ac);
            var acOff     = new AcOff(ac);

            //setup the invoker/remote control
            var remoteController = new RemoteController();

            remoteController.InsertNewOnCmd(lightsOn);
            remoteController.InsertNewOnCmd(acOn);
            remoteController.InsertNewOffCmd(lightsOff);
            remoteController.InsertNewOffCmd(acOff);

            //invoke the receiver
            remoteController.PressButtonOn(0);
            remoteController.PressButtonOn(1);
            remoteController.PressButtonOff(0);
            remoteController.PressButtonOff(1);

            Console.ReadLine();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light    light             = new Light();
            LightOn  lightOn           = new LightOn(light);
            LightOff lightOff          = new LightOff(light);

            remote.SetCommand(0, lightOn, lightOff);
            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);

            GarageDoor      door      = new GarageDoor();
            GarageDoorOpen  doorOpen  = new GarageDoorOpen(door);
            GarageDoorClose doorClose = new GarageDoorClose(door);

            remote.SetCommand(1, doorOpen, doorClose);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bgokoglu/HFPatterns
        static void Main(string[] args)
        {
            SimpleRemoteControl remote = new SimpleRemoteControl();
            Light light = new Light();
            LightOn lightOn = new LightOn(light);
            LightOff lightOff = new LightOff(light);

            remote.SetCommand(0, lightOn, lightOff);
            remote.OnButtonWasPressed(0);
            remote.OffButtonWasPressed(0);

            GarageDoor door = new GarageDoor();
            GarageDoorOpen doorOpen = new GarageDoorOpen(door);
            GarageDoorClose doorClose = new GarageDoorClose(door);

            remote.SetCommand(1, doorOpen, doorClose);
            remote.OnButtonWasPressed(1);
            remote.OffButtonWasPressed(1);
        }