What the decorator pattern is
The decorator pattern is a software design pattern that lets you add behavior to an individual object by wrapping it in another object, called a decorator, without affecting other objects of the same class. The decorator shares the object's interface and adds its own behavior around the wrapped object's. This provides a flexible way to extend what a single object does. Because the behavior is added at runtime by wrapping, it offers an alternative to defining new subclasses for every variation you might need.
Wrapping an object
A decorator works by holding a reference to the object it wraps and presenting the same interface to clients. When a client calls the decorator, the decorator can add behavior before or after passing the call to the wrapped object. Because it looks like the original object from the outside, it can be used anywhere the original could, while quietly enhancing the behavior.
Adding behavior per object
Unlike changing a whole class, the decorator pattern adds behavior to specific objects. One object can be decorated while others of the same class are left alone. This selective enhancement is a key advantage: you can tailor individual objects with extra behavior as needed, rather than altering the class and affecting everything built from it.
Layering decorators
Decorators can be stacked, with one decorator wrapping another, each adding its own behavior. This layering lets you combine enhancements flexibly, building up an object's behavior piece by piece. Because each decorator shares the common interface, the layers compose cleanly. This makes the decorator pattern a flexible alternative to creating many subclasses for every combination of features.
Decorator among design patterns
The decorator is one of the classic design patterns for extending behavior. Describing a design as using the decorator pattern conveys that behavior is added by wrapping objects rather than by subclassing. Recognizing this pattern helps developers extend objects flexibly and discuss how behavior is composed at runtime.
Why it matters
The decorator pattern is a valuable design pattern for extending behavior. Understanding what it is - adding behavior to an object by wrapping it - clarifies a flexible alternative to subclassing. For anyone learning software design, it is a valuable concept to understand.
Related on Skillo
See also: What is the adapter pattern? Explained, What is a design pattern? Explained.
Sources
Published date reflects the original event date (2026-04-07). This article is original Skillo editorial written from the sources above; facts were verified in September 2026.
Leave a Reply