liveBook · Manning

Decorator design pattern

Also called decorator pattern

The decorator design pattern adds behavior or responsibilities to an object by wrapping it in another object that preserves 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 →

Also covered in

What to know first

Related concepts

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.