Command

Command encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. Commands are an object oriented replacement for callbacks.

Command Class Diagram

Examples:

Swing Action Objects. Swing uses Command pattern to separate the GUI components from the actual code which processes the generated events. You can configure a JButton object with a concrete Action implementation which can then forward the request to an object implementing the application logic.

In this example, the JButton acts as an Invoker, calling the actionPerformed method of a concrete Action (Command) object. The JButton instance is not aware of the object that actually handles the command request.

The Action object then delegates the call to a Receiver object which does not know who issued the request but knows how to process it. The receiver object can be modified or completely changed to another object without affecting the code in JButton. Similarly, new objects sending the requests can be added without affecting the Receiver object.




Last Updated: $Date: 2000/07/29 18:03:07 $ by $Author: jpl $