Decorator design pattern
The decorator design pattern adds behavior or responsibilities to an object by wrapping it in another object that preserves its interface.
Software Design for Python Programmers
The Decorator Design Pattern is a structural design pattern that dynamically attaches additional responsibilities to an object by wrapping it with objects that share its interface.
- How it is used
- Models runtime extension of object responsibilities when inheritance or aggregation would hardcode the available variations.
- How deep it goes
- Explains the pattern through a flawed ticket design, wrapper classes, recursive cost delegation, and a generic role mapping.
- Examples
- Uses base tickets, pregame parties, VIP seating, and repeated drink coupons to demonstrate inflexible attributes and flexible wrapper chains.
- What you can do after
- Build it from scratch by defining a shared component, a wrapper holding that component, and decorators that extend delegated behavior.
Read how Software Design for Python Programmers explains decorator design pattern →
Object-Oriented Software Design in C++
A structural design pattern that attaches additional responsibilities to an object dynamically through wrapper objects that preserve the wrapped object's interface.
- How it is used
- Uses wrapper objects to add ticket attributes and behaviors dynamically while keeping decorated and undecorated tickets interchangeable.
- How deep it goes
- Explains the problem, refactoring, inheritance structure, nested delegation, and C++ implementation, but does not discuss broader trade-offs.
- Examples
- Demonstrates base tickets decorated with party access, VIP seating, and repeated drink coupons.
- What you can do after
- Builds a C++ decorator chain that calculates combined responsibilities through a shared Ticket interface.
Read how Object-Oriented Software Design in C++ explains decorator design pattern →
Also covered in
- AI-Powered Developer: Build software with ChatGPT and Copilot
- Kotlin in Action, 2E
- Clean Applications with Hexagonal ArchitectureIn early access (MEAP)
- Go in Practice, Second Edition
What to know first
- design patternA design pattern is a reusable, general solution structure for a recurring software design problem.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- hardcodingHardcoding is embedding fixed values, rules, configuration, or behavioral choices directly in code or another artifact rather than supplying or deriving them separately.
- inheritanceInheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
Related concepts
- design patternkind of · A design pattern is a reusable, general solution structure for a recurring software design problem.
- command and query bususes · A routing mechanism that dispatches commands and queries to their corresponding application handlers.
- hardcodingaddresses · Hardcoding is embedding fixed values, rules, configuration, or behavioral choices directly in code or another artifact rather than supplying or deriving them separately.
- inheritancealternative to · Inheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
- patternkind of · A pattern is a reusable approach to solving a recurring problem within a particular context.
Questions about decorator design pattern
What is decorator design pattern?
The decorator design pattern adds behavior or responsibilities to an object by wrapping it in another object that preserves its interface.
Which Manning books explain decorator design pattern?
Software Design for Python Programmers and Object-Oriented Software Design in C++.
What should I know before learning decorator design pattern?
Manning books that teach decorator design pattern usually introduce design pattern, attribute, hardcoding and inheritance first.
What is the difference between decorator design pattern and inheritance?
The decorator design pattern adds behavior or responsibilities to an object by wrapping it in another object that preserves its interface. Inheritance is a mechanism in which a derived type or descendant element receives properties or behavior from a parent, subject to rules that may allow specialization or overriding.
What is decorator design pattern a kind of?
Decorator design pattern is a kind of design pattern. A design pattern is a reusable, general solution structure for a recurring software design problem.
What is decorator design pattern also called?
Decorator design pattern is also called decorator pattern.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

