Applied Design Patterns with Java

Behavioral :: Command (233) {C ch 17}


Collaborations

The following Interaction (Sequence) Diagram shows the interactions between these objects. It illustrates how Command decouples the invoker from the receiver (and the request it carries out):

Consequences

Command has the following benefits and liabilities:

  1. Reduced coupling. Command decouples the object that invokes the operation from the one that knows how to perform it. The use of Delegates makes this possible.
  2. Reusability. Commands are first-class objects. They can be manipulated and extended like any other object.
  3. You can assemble Commands into a composite Command. An example is the MacroCommand class described earlier. In general, composite Commands are an instance of the Composite (163) pattern.
  4. Extensibility. It's easy to add new Commands, as there is no need to change existing classes.

Catalog Behavioral Prev Next