Esempio n. 1
0
 // Constructor
 public CalculatorCommand(Calculator calculator,
   char @operator, int operand)
 {
     this._calculator = calculator;
     this._operator = @operator;
     this._operand = operand;
 }
Esempio n. 2
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        static void Main()
        {
            Calculator myCalculator = new Calculator();

            // Create user and let her compute  (Invoker)
            User user = new User();

            Command add100command = new CalculatorCommand(myCalculator, '+', 100);
            Command sub50command = new CalculatorCommand(myCalculator, '-', 50);
            Command multi10command = new CalculatorCommand(myCalculator, '*', 10);
            Command div2command = new CalculatorCommand(myCalculator, '/', 2);

            // User presses calculator buttons
            //Set the command
            //And executes the command
            user.ComputeCalculatorCommand(add100command);
            user.ComputeCalculatorCommand(sub50command);
            user.ComputeCalculatorCommand(multi10command);
            user.ComputeCalculatorCommand(div2command);

            // Undo 4 commands
            user.Undo(4);

            // Redo 3 commands
            user.Redo(3);

            // Wait for user
            Console.ReadKey();
        }