static void Main(string[] args) { var invoker = new Invoker(); var calculator = new Calculator(); var command1 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Add, 10); var command2 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Multiply, 5); var command3 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Subtract, 5); var command4 = new CalculatorCommand(calculator, CalculatorCommand.Operation.Divide, 5); invoker.Command = command1; invoker.Invoke(); invoker.Command = command2; invoker.Invoke(); invoker.Command = command3; invoker.Invoke(); invoker.Undo(); invoker.Command = command4; invoker.Invoke(); Console.WriteLine($"Result is : {calculator.Value}"); }
static void Main(string[] args) { Receiver receiver = new Receiver(); ICommand cmd = new PrintCommand(receiver); Invoker invoker = new Invoker(); invoker.StoreCommand(cmd); invoker.Invoke(); }
static void Main(string[] args) { IInvoker invoker; Console.WriteLine("Press c for Copy and p for Paste"); while (true) { var command = Console.ReadLine(); if (command == "c") { invoker = new Invoker(new CopyCommand(new Receiver())); invoker.Invoke(); } else if (command == "p") { invoker = new Invoker(new PasteCommand(new Receiver())); invoker.Invoke(); } } }