Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //创建命令管理者
            Invoker invoker = new Invoker();

            //创建执行者和命令 并指定命令执行者
            Receiver        r  = new Receiver();        //执行者
            ConcreteCommand c1 = new ConcreteCommand(); //创建命令

            c1.Receiver = r;                            //指定执行者
            ConcreteCommandB c2 = new ConcreteCommandB();

            c2.Receiver = r;

            invoker.SetCommand(c1);
            invoker.SetCommand(c2);
            invoker.SetCommand(c1);
            invoker.ExecuteCommand();

            Console.WriteLine("------------------------");

            invoker.RemoveCommand(c2);
            invoker.ExecuteCommand();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Account account   = new Account();
            Command commandIn = new MoneyInCommand(account, 500);
            Invoker invoker   = new Invoker();

            invoker.SetCommand(commandIn);
            invoker.ExecuteCommand();
            Console.WriteLine("The current amount is " + account.GetTotalAmout());

            Command commandOut = new MoneyOutCommand(account, 300);

            invoker.SetCommand(commandOut);
            invoker.ExecuteCommand();
            Console.WriteLine("The current amount is " + account.GetTotalAmout());

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Receiver r = new Receiver();
            Command  c = new ConcreteCommand(r);
            Invoker  i = new Invoker();

            i.SetCommand(c);
            i.ExecuteCommand();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Receive receive = new Receive();

            ICommand command = new AddCommand(receive);

            ICommand command1 = new RemoveCommand(receive);

            Invoker invoker = new Invoker();

            invoker.SetCommand(command);

            invoker.SetCommand(command1);

            invoker.Exceute();

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Receiver receiver = new Receiver();
            Command  command  = new ConcreteCommand(receiver);
            Invoker  invoke   = new Invoker();

            invoke.SetCommand(command);
            invoke.ExecuteCommand();

            Console.ReadKey();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Receiver receiver = new Receiver();
            Command command =new ConcreteCommand(receiver);
            Invoker invoke = new Invoker();

            invoke.SetCommand(command);
            invoke.ExecuteCommand();

            Console.ReadKey();
        }
        private static void Main(string[] args)
        {
            Receiver r = new Receiver();
            Command  c = new ConcreteCommand(r);
            Invoker  i = new Invoker();

            // Set and execute command
            i.SetCommand(c);
            i.ExecuteCommand();

            Console.Read();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Receiver r = new Receiver();
            Command c = new ConcreteCommand(r);
            Invoker i = new Invoker();

            // Set and execute command
            i.SetCommand(c);
            i.ExecuteCommand();

            Console.Read();
        }
Ejemplo n.º 9
0
        //客户端代码: 创建一个具体命令对象并设定它的接受者
        static void Main(string[] args)
        {
            //烤肉师傅
            Receiver r = new Receiver();
            //服务员
            Command c = new ConcreteCommand(r);
            //顾客
            Invoker i = new Invoker();

            i.SetCommand(c);
            i.ExecuteCommand();
        }