liveBook · Manning

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.

How 2 Manning books explain it

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

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.