Beispiel #1
0
        static void Main(string[] args)
        {
            // Initialize the receiver - in our case; the display
            Display display = new Display(10);								// 10

            // Initialize the invoker - in our case; the equals button
            EqualsButton equalsButton = new EqualsButton();

            // Add some commands to the invoker's queue
            equalsButton.pushCommand(new AddCommand(10, display));			// 20
            equalsButton.pushCommand(new SubtractCommand(1, display));		// 19
            equalsButton.pushCommand(new AddCommand(20, display));			// 39
            equalsButton.pushCommand(new SubtractCommand(13, display));		// 26
            equalsButton.pushCommand(new AddCommand(27, display));			// 53
            equalsButton.pushCommand(new SubtractCommand(49, display));		// 4
            equalsButton.pushCommand(new AddCommand(201, display));			// 205

            // Let the invoker do its job - Now displaying: 205
            equalsButton.invoke();

            // Lets undo the last three commands - Now displaying: 26
            equalsButton.undo(3);
            Console.ReadLine();
        }
 // Constructor
 public SubtractCommand(int value, Display display)
 {
     this._display = display;
     this._value = value;
 }
 // Constructor
 public AddCommand(int value, Display display)
 {
     this._display = display;
     this._value = value;
 }