Command

Intent

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support for undoable operations.

      -Design Patterns, GoF

 

Structure

A class diagram from JavaWorld.com:

 

 

And a sequence diagram:

 

 

Questions

1) How is the Command pattern the Object-Oriented version of a callback function?

2) How can this pattern help deal with system crashes?

3) How does using the Command pattern help consistently delineate transaction boundaries?

4) What is the relationship between the Command and the Receiver?

5) How much logic should the Command take on?

6) How would you support an undo operation with the Command Pattern?

7) What happens if the command needs some information about the application in order to do its job?

8) In what situations is a Command like an Adaptor?