Beispiel #1
0
        static void Main(string[] args)
        {
            var invoker = new Invoke();
            var text    = new MyText();

            text.WriteNewLine("Hi I am Ahmed \n");
            text.WriteNewLine("Hello This is a mistake \n");
            text.Print();
            var undoCommand = new UndoCommand(text);
            var redoCommand = new RedoCommand(text);

            invoker.SetCommand(undoCommand);
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Undo Completed");
            Console.WriteLine("==============================================");
            text.Print();
            text.WriteNewLine("Hell I now write good \n");
            text.WriteNewLine("Let's complete our work \n");
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Undo Completed");
            Console.WriteLine("==============================================");
            text.Print();
            invoker.SetCommand(redoCommand);
            invoker.ExecuteCommand();
            Console.WriteLine("==============================================");
            Console.WriteLine("Redo Completed");
            Console.WriteLine("==============================================");
            text.Print();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Receiver receive = new Robot();
            Command  comand  = new ConcreteCommand(receive);
            Invoke   invoke  = new Invoke(comand);

            invoke.ExecuteCommand();
            Console.ReadKey();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("***Command Pattern Demo***\n");
            /*Client holds  both the Invoker and Command Objects*/
            Invoke   invoker          = new Invoke();
            Receiver intendedreceiver = new Receiver();

            MyUndoCommand undoCmd = new MyUndoCommand(intendedreceiver);

            invoker.SetCommand(undoCmd);
            invoker.ExecuteCommand();

            MyRedoCommand redoCmd = new MyRedoCommand(intendedreceiver);

            invoker.SetCommand(redoCmd);
            invoker.ExecuteCommand();
            Console.ReadKey();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Receiver r = new Receiver();
            Command  c = new ConcreteCommand(r);
            Invoke   i = new Invoke(c);

            i.ExecuteCommand();
            Console.WriteLine("Hello World!");
        }
Beispiel #5
0
        public static void BaseSample()
        {
            var receiver = new Receiver();
            var command  = new ConcreteCommand(receiver);
            var invoke   = new Invoke(command);

            invoke.ExecuteCommand();
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            // 初始化Receiver、Invoke和Command
            Receiver r = new Receiver();
            Command  c = new ConcreteCommand(r);
            Invoke   i = new Invoke(c);

            // 院领导发出命令
            i.ExecuteCommand();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            WashMachine washMachine = new WashMachine();
            Stereo      stereo      = new Stereo();
            Invoke      invoke      = new Invoke();

            invoke.SetCommand(new OffStereo(stereo));
            invoke.ExecuteCommand();

            invoke.SetCommand(new OnStereo(stereo));
            invoke.ExecuteCommand();

            invoke.SetCommand(new OnWasMachine(washMachine));
            invoke.ExecuteCommand();

            invoke.SetCommand(new OffWashMachine(washMachine));
            invoke.ExecuteCommand();


            Console.ReadKey();
        }