DESIGN PATTERNS SERIES
How to Dynamically Add Behaviors With Decorator Pattern
Everything you need to know about Decorator
What is the Decorator Pattern?
The Decorator Pattern is a structural design pattern that allows you to dynamically add behavior to a class without making changes to that class. In other words, it uses composition instead of inheritance to add the functionality of an object.
Elements of the Decorator Pattern
IComponent
IComponent is an interface. It is an abstraction of what we want to decorate. You can also use an abstract class.
Component
The component is a class that you want to add behavior. The component needs to implement an interface or extend an abstract class.
Decorator
The decorator class will implement the same interface or abstract class as the Component class.
The decorator’s constructor always takes an object implementing the same interface as a…