Hey, I have just reduced the price for all products. Let's prepare our programming skills for the post-COVID era. Check it out »
Decorator

Decorator in PHP

Decorator is a structural 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.

Usage of the pattern in PHP

Complexity:

Popularity:

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

Identification: Decorator can be recognized by creation methods or constructor that accept objects of the same class or interface as a current class.

Decorator in Other Languages

Design Patterns: Decorator in Java Design Patterns: Decorator in C# Design Patterns: Decorator in C++ Design Patterns: Decorator in Python Design Patterns: Decorator in Ruby Design Patterns: Decorator in Swift Design Patterns: Decorator in TypeScript Design Patterns: Decorator in Go