Origin: |
GoF 95 |
Reason: |
To allow operations on commands such as sequencing and undoing.
|
Synopsis: |
Represent commands as encapsulated objects.
Provide a command manager to execute commands.
|
Example: |
A word processing program should be able to undo and
redo previously executed commands.
|
Solution: |
AbstractCommand |
Interface for executing a command.
Has abstract methods such as doit and undoit.
|
ConcretCommand |
Implement a specific command.
Constructor has required parameters.
Specializes doit and undoit methods.
|
Invoker |
Asks a command to do its job.
May create the command.
|
CommandManager |
Manages a collection of commands to support "history" requests.
Can be quite general.
|
|
See also: |
Snapshot
(coarser alternative to undo)
Little Language
(may use this pattern)
|