コード例 #1
0
        public void Test()
        {
            var receiver = new Receiver();
            var command  = new ConcreteCommand(receiver);
            var invoker  = new Invoker {
                Command = command
            };

            invoker.ExecuteCommand();
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: PlumpMath/DesignPatternCS
        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();
        }
コード例 #4
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();
        }
コード例 #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
ファイル: Program.cs プロジェクト: bhay3s/DesignPatterns
        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();
            }
        }