Decorator design pattern
The decorator design pattern is a structural pattern that dynamically adds responsibilities or behavior to an object by wrapping it with objects that preserve 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 →
Related concepts
- design patternkind of · A design pattern is a reusable, general solution structure for a recurring software design problem in a particular context.
- inheritancealternative to · Inheritance is a mechanism by which a child type or element receives properties, values, or behavior from a parent, subject to system rules and possible overrides.
- hardcodingaddresses · Hardcoding is embedding fixed values, rules, configuration, or behavioral choices directly in a program or its implementation rather than supplying or deriving them separately.
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.

