🎨 Design Patterns (Gang of Four)
Beginner
What is the Command design pattern?
Answer
The Command pattern encapsulates a request as an object, allowing you to parameterize clients with different requests, queue them, log them, and support undoable operations. Each command object implements an execute() method. For example, a text editor's "Bold" action becomes a BoldCommand object. This enables: storing commands in a history stack for undo/redo, serializing commands to a queue for scheduled execution, and implementing macro recording by grouping multiple commands. GUI buttons that execute different actions depending on context are a textbook use case.
Previous
What is the Chain of Responsibility design pattern?
Next
What is the Iterator design pattern?