Пример #1
0
        public void Test()
        {
            var receiver = new Receiver();
            var command  = new ConcreteCommand(receiver);
            var invoker  = new Invoker {
                Command = command
            };

            invoker.ExecuteCommand();
        }
Пример #2
0
        public void RunCommand()
        {
            Invoker         invoker  = new Invoker();
            Receiver        receiver = new Receiver();
            ConcreteCommand command  = new ConcreteCommand(receiver);

            command.Parameter = "YO";
            invoker.Command   = command;
            invoker.ExecuteCommand();
        }
Пример #3
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Execute()
        {
            // Create receiver, command, and invoker
            Receiver receiver = new Receiver();
            Command  command  = new ConcreteCommand(receiver);
            Invoker  invoker  = new Invoker();

            // Set and execute command
            invoker.SetCommand(command);
            invoker.ExecuteCommand();
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            // Create receiver, command, and invoker
              Receiver receiver = new Receiver();
              Command command = new ConcreteCommand(receiver);
              Invoker invoker = new Invoker();

              // Set and execute command
              invoker.SetCommand(command);
              invoker.ExecuteCommand();

              // Wait for user
              Console.ReadKey();
        }
Пример #5
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            // Create receiver, command, and invoker
            Receiver receiver = new Receiver();
            Command  command  = new ConcreteCommand(receiver);
            Invoker  invoker  = new Invoker();

            // Set and execute command
            invoker.SetCommand(command);
            invoker.ExecuteCommand();

            // Wait for user
            Console.ReadKey();
        }
Пример #6
0
        static void Main(string[] args)
        {
            var reciever = new Reciever(); // class that does the actual work


            // object which encapsulates worker object
            var dowork         = new DoWorkCommand(reciever);
            var doOtherWork    = new DoOtherWorkCommand(reciever);
            var doYetOtherWork = new DoYetOtherWorkCommand(reciever);


            var invoker = new Invoker();
            // dynamically update the receiver class
            var cmdList = new List <string>()
            {
                "do work", "do yet other work", "do other work"
            };

            foreach (var cmd in cmdList)
            {
                switch (cmd)
                {
                case "do work":
                    invoker.Command = dowork;
                    break;

                case "do yet other work":
                    invoker.Command = doYetOtherWork;
                    break;

                case "do other work":
                default:
                    invoker.Command = doOtherWork;
                    break;
                }

                invoker.ExecuteCommand();
            }
        }