0
0
LLDsystem_design~12 mins

Decorator pattern in LLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Decorator pattern

The Decorator pattern allows adding new behaviors to objects dynamically without changing their structure. It helps to extend functionalities by wrapping objects with decorator classes that add features before or after delegating to the original object.

Key requirements include flexibility to add or remove features at runtime and keeping the original object code unchanged.

Architecture Diagram
User
  |
  v
+-----------------+
| Component       |
| (Interface)     |
+-----------------+
        ^
        |
+-----------------+       +-------------------+
| ConcreteComponent|       | Decorator         |
| (Original Object)|       | (Wraps Component) |
+-----------------+       +-------------------+
                                ^
                                |
                      +-------------------+
                      | ConcreteDecorator |
                      | (Adds Behavior)   |
                      +-------------------+
Components
Component
interface
Defines the common interface for objects and decorators.
ConcreteComponent
service
Original object that provides core functionality.
Decorator
wrapper
Abstract class that wraps a Component and delegates calls.
ConcreteDecorator
wrapper
Adds new behavior before or after delegating to the wrapped Component.
Request Flow - 6 Hops
UserConcreteDecorator
ConcreteDecoratorDecorator
DecoratorConcreteComponent
ConcreteComponentDecorator
DecoratorConcreteDecorator
ConcreteDecoratorUser
Failure Scenario
Component Fails:ConcreteDecorator
Impact:If the decorator fails, added behaviors are lost but original object still works if called directly.
Mitigation:Use fallback to call ConcreteComponent directly or chain multiple decorators to isolate failures.
Architecture Quiz - 3 Questions
Test your understanding
Which component in the Decorator pattern is responsible for adding new behavior?
AConcreteComponent
BComponent interface
CConcreteDecorator
DUser
Design Principle
The Decorator pattern demonstrates how to extend object behavior dynamically by wrapping objects. It promotes flexibility and adheres to the open-closed principle by allowing new features without modifying existing code.