All PatternsBehavioral
Command
Encapsulates a request as an object.
Undo/redo operationsTask queuesMacro recording
Understanding Command
The Command pattern encapsulates a request as an object, letting you parameterize clients with different requests, queue requests, log them, and support undoable operations.
How It Works
LightOn
LightOff
Commands
Command Queue
Cmd
Cmd
...
💡 Light
OFF
Actions as objects
1
Action as Object
Encapsulate a request as an object.
1 / 4
Basic Implementation
Remote control with undo functionality:
main.go
Loading editor...
Real-World Example: Text Editor
Text operations as commands with macro support:
main.go
Loading editor...