Decorator in C#
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 C#
Usage examples: The Decorator is pretty standard in C# 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.
This example illustrates the structure of the Decorator design pattern. It focuses on answering these questions:
- What classes does it consist of?
- What roles do these classes play?
- In what way the elements of the pattern are related?
Program.cs: Conceptual Example
Output.txt: Execution result
Decorator in Other Languages