Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.

Similar presentations


Presentation on theme: "Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003."— Presentation transcript:

1 Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003

2 Software Design & Documentation – Design Pattern: Command Design Pattern: Command Creational Structural Behavioral 

3 Software Design & Documentation – Design Pattern: Command Intent / Definition Encapsulate a request as an object… …thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.

4 Software Design & Documentation – Design Pattern: Command When to Use… Parameterize objects by an action to perform. Specify, queue, and execute requests at different times. (independent lifetime) Support an undo operation. (provided Unexecute operation added) Support logging changes so they can be reapplied in case of a system crash. Structure a system around high-level operations built on primitive operations. (e.g. Transaction processing – store & read data)

5 Software Design & Documentation – Design Pattern: Command Participants Command ConcreteCommand Client Invoker Receiver

6 Software Design & Documentation – Design Pattern: Command Structure UML Diagram

7 Software Design & Documentation – Design Pattern: Command Consequences Commands are first-class objects – meaning they can be manipulated just like any other object. You can assemble commands into a composite command. It’s easy to add new Commands because you don’t have to change existing classes. Command decouples the object that invokes the operation from the one that knows how to perform it.

8 Software Design & Documentation – Design Pattern: Command Implementation Consider the following: How intelligent should a command be? Supporting undo and redo. Avoiding error accumulation in the undo process.

9 Software Design & Documentation – Design Pattern: Command Example: Undo & Redo Supporting undo and redo & Avoiding error accumulation Commands can support undo and redo w/Unexecute or Undo operation ConcreteCommand class might need to store additional state info Levels of undo (One, Multiple – history list?) Command can store lots of data to avoid error accumulation


Download ppt "Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003."

Similar presentations


Ads by Google