Example #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();
        }
Example #2
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();
        }
Example #3
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();
        }
Example #4
0
        static void Main(string[] args)
        {
            //基本结构

            Receiver r       = new Receiver();
            Command  command = new ConcreteCommand(r);
            Invoke   i       = new Invoke();

            i.SetCommand(command);
            i.ExcuteCommand();

            Console.Read();
        }