Command Pattern: Encapsulating Actions
Wrap requests as Command objects to support undo/redo and macro recording.
The Command Intent
Command encapsulates a request as an object, allowing parameterization of clients with different requests, queuing, logging, and undoable operations.
Command Interface
Define an interface with an execute() method and optionally an undo() method. Each command object knows how to perform and reverse one action.
public interface Command {
void execute();
void undo();
}All lessons in this course
- Observer Pattern: Event Notification
- Strategy Pattern: Interchangeable Algorithms
- Command Pattern: Encapsulating Actions
- Template Method: Defining Algorithm Skeletons