The Command Processor pattern can be used to realize the controller component in the Model-View-Controller Architecture:
Here's the pattern:
Here is a typical object interaction:
There are several variations of this pattern. The variation shown above is called the "smart command" variation because commands know how to execute themselves.
In the "smart processor" variation, commands can be simple strings. The execute method of the command processor is a giant multi-way conditional:
if (cmmd instanceof ConcreteCommand1) {
executeConcreteCommand1();
} else if cmmd instanceof ConcreteCommand2) {
executeConcreteCommand2();
} else if (cmmd instanceof ConcreteCommand3) {
executeConcreteCommand3();
} else ...
The Memento Pattern is often used to encapsulate a snapshot of the state of the model before execution of a command. To undo a command, the memento is passed back to the model.