Bird
0
0
LLDsystem_design~12 mins

Command pattern for undo in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Command pattern for undo

The system implements the Command design pattern to support undo functionality. It allows users to execute commands that change the system state and then undo those changes step-by-step.

Key requirements include tracking executed commands, reversing their effects, and maintaining a history stack for undo operations.

Architecture Diagram
User
  |
  v
Invoker (Command Manager)
  |
  v
+-----------------+      +----------------+
| ConcreteCommand  | ---> | Receiver       |
| (Execute/Undo)   |      | (Performs work)|
+-----------------+      +----------------+
  |
  v
Command History Stack
Components
User
actor
Initiates commands to change system state
Invoker (Command Manager)
service
Receives commands from user, executes them, and manages undo stack
ConcreteCommand
command
Encapsulates a request with execute and undo methods
Receiver
service
Performs the actual work requested by commands
Command History Stack
storage
Stores executed commands to enable undo operations
Request Flow - 8 Hops
UserInvoker (Command Manager)
Invoker (Command Manager)ConcreteCommand
ConcreteCommandReceiver
Invoker (Command Manager)Command History Stack
UserInvoker (Command Manager)
Invoker (Command Manager)Command History Stack
Invoker (Command Manager)ConcreteCommand
ConcreteCommandReceiver
Failure Scenario
Component Fails:Command History Stack
Impact:Undo operations fail because command history is lost or corrupted
Mitigation:Implement persistent storage or backup for command history; notify user of undo unavailability
Architecture Quiz - 3 Questions
Test your understanding
Which component is responsible for executing and undoing commands?
AConcreteCommand
BReceiver
CInvoker (Command Manager)
DCommand History Stack
Design Principle
This architecture cleanly separates command invocation, execution, and undo logic. The Command pattern encapsulates requests as objects, enabling flexible undo by storing commands in a history stack. This design promotes loose coupling and easy extension.