Bird
0
0
LLDsystem_design~12 mins

Command pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Command pattern

The Command pattern is a design approach that turns requests or simple operations into objects. This allows for flexible command execution, queuing, logging, and undo functionality. It helps separate the object that issues a request from the one that knows how to perform it.

Architecture Diagram
User
  |
  v
Invoker
  |
  v
Command Interface <-----> Concrete Command
  |                         |
  v                         v
Receiver <------------------
Components
User
actor
Initiates commands by interacting with the Invoker
Invoker
service
Holds and triggers commands without knowing their implementation
Command Interface
interface
Defines the execute method for commands
Concrete Command
service
Implements the command interface and calls actions on the Receiver
Receiver
service
Performs the actual work when a command is executed
Request Flow - 5 Hops
UserInvoker
InvokerConcrete Command
Concrete CommandReceiver
ReceiverInvoker
InvokerUser
Failure Scenario
Component Fails:Concrete Command
Impact:Command execution fails, so the requested action is not performed
Mitigation:Invoker can catch errors and notify User or retry; commands can be logged for replay
Architecture Quiz - 3 Questions
Test your understanding
Which component is responsible for performing the actual work in the Command pattern?
AReceiver
BInvoker
CConcrete Command
DUser
Design Principle
The Command pattern cleanly separates the requester of an action from the object that performs it. This allows commands to be stored, queued, logged, or undone, improving flexibility and decoupling in software design.