juniorDesign Patterns
What is the Decorator Pattern?
Updated Apr 28, 2026
Short answer
A structural pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects.
Deep explanation
Decorator uses aggregation/composition instead of inheritance to extend behavior. You can wrap an object multiple times, combining behaviors at runtime without creating an explosion of subclasses.
Real-world example
Adding toppings to a base pizza, where each topping acts as a decorator modifying the cost and description.
Common mistakes
- Creating a deep, complex stack of decorators that becomes impossible to debug or trace.
Follow-up questions
- Why favor composition over inheritance here?