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
- One action can be represented in many ways, like drop-down menu, buttons and popup menu.
- Need a callback function, i.e., register it somewhere to be called later.
- Specify and execute the request at different time
- Need to undo an action by storing its states for later retrieving.
- Decouple the object with its trigger
- Easily to be extensible by not touching the old structure.
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
