Intent

Streamlize objects by providing an interface to encapsulate a request and make the interface implemented by subclasses in order to parameterize the clients.

Where to use & benefits

Structure


Participants

Command  (IShapeCommand)
declares an interface for executing an operation.

ConcreteCommand   (ShapeDrawCommands)
defines a binding between a Receiver object and an action.

Invoker  (AppletPainter)
It asks the command to carry out the request.

Receiver  (IShapeDrawer)
It knows how to perform the operations associated with carrying out a request.

Client  (MainApplet)
creates a ConcreteCommand object and sets its receiver.

Example

In the demonstration application, AppletPainter class invokes the IShapeCommand to execute the encapsulated commands to draw the shapes in applet UI. ShapeDrawCommands class uses the IShapeDrawer interface to execute the commands.

Class Diagram


Source Code Links