コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Commands (ON/OFF/DIM/BRIGHTEN) : ");
            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 if (cmd == "DIM")
            {
                s.StoreAndExecute(switchDown);
            }
            else if (cmd == "BRIGHTEN")
            {
                s.StoreAndExecute(switchDown);
            }
            else
            {
                Console.WriteLine("Command \"ON\" or \"OFF\" is required.");
            }

            Console.ReadKey();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Commands (ON/OFF) : ");
            string command = Console.ReadLine();

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

            Switch s = new Switch();

            if (command == "ON")
            {
                s.AddCommand(switchUp);
                s.ExecuteCommand(switchUp);
            }
            else if (command == "OFF")
            {
                s.AddCommand(switchDown);
                s.ExecuteCommand(switchDown);
            }
            else
            {
                Console.WriteLine("Command \"ON\" or \"OFF\" is required.");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Light    lamp       = new Light();
            ICommand switchUp   = new FlipUpCommand(lamp);
            ICommand switchDown = new FlipDownCommand(lamp);

            Switch s = new Switch();

            s.StoreAndExecute(switchUp);

            s.StoreAndExecute(switchDown);
        }