🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »
Decorator

Decorator in PHP

Decorator is a Conceptual pattern that allows adding new behaviors to objects dynamically by placing them inside special wrapper objects.

Using decorators you can wrap objects countless number of times since both target objects and decorators follow the same interface. The resulting object will get a stacking behavior of all wrappers.

Learn more about Decorator

Usage of the pattern in PHP

Complexity:

Popularity:

Usage examples: The Decorator is pretty standard in PHP code, especially in code related to streams.

Decorator in Other Languages

Decorator in Java Decorator in C# Decorator in Python Decorator in Ruby Decorator in Swift Decorator in TypeScript