Exemplo n.º 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();
        }
Exemplo n.º 2
0
 public AcOff(AirCondition _airCondition)
 {
     airCondition = _airCondition;
 }