Summary
When you have an object type that needs a variety of behaviors that you might compose in various ways, the DECORATOR pattern offers a flexible alternative to creating a class for every possible behavioral combination. The Java class libraries provide a classic example of DECORATOR in the implementation of input and output streams. In application code, you can apply DECORATOR to set up function hierarchies. This lets you create a large family of function objects from a fixed set of function classes.
It is easy to mistake examples of “decoration” in a design as instances of DECORATOR. A design may allow runtime customization of an object's attributes and its behavior without using DECORATOR. The intent of DECORATOR is to let you compose ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access