The decorator pattern allows adding new functionality to an individual object dynamically at runtime without affecting other objects. It provides a flexible alternative to subclassing for extending functionality. The document describes using the decorator pattern to model a coffee shop that can create different coffee drink combinations by decorating a basic drink object with condiments like mocha or whip cream. The key aspects are that decorators have the same supertype as the object they decorate, decorators can be applied at multiple levels, and decorators add their own behavior before or after delegating to the decorated object.
Related topics: