Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Commands (ON/OFF) : ");
            string cmd = Console.ReadLine();

            Light    lamp       = new Light();
            ICommand switchUp   = new FlipUpCommand(lamp);
            ICommand switchDown = new FlipDownCommand(lamp);

            Switch s = new Switch();

            if (cmd == "ON")
            {
                s.StoreAndExecute(switchUp);
            }
            else if (cmd == "OFF")
            {
                s.StoreAndExecute(switchDown);
            }
            else
            {
                Console.WriteLine("Command \"ON\" or \"OFF\" is required.");
            }

            Console.ReadKey();
        }
Exemplo n.º 2
0
        public static void Main()
        {
            var      light      = new Light();
            ICommand switchUp   = new FlipUpCommand(light);
            ICommand switchDown = new FlipDownCommand(light);

            var lightSwitch = new LightSwitch();

            lightSwitch.StoreAndExecute(switchUp);
            lightSwitch.StoreAndExecute(switchDown);
        }