The first structural pattern that we will discuss is the decorator pattern. It introduces you to the object substitution by adding new functionalities or behaviors.
The main objective of this pattern is to dynamically add new functionalities to an object. The interface of the object will not be modified, so from the client's perspective, this is fully transparent.
This pattern is an alternative to the addition of a subclass that adds functionalities to its parent class. A key implementation point in the decorator pattern is that decorators both inherit the original class and contain an instantiation of it.
This pattern can be used when:
A system adds dynamically new functionalities to an object, without having to modify its interface, which means without having to modify the client of this object
A system manages the behavior that can be dynamically removed
The use of inheritance is not a good option because of an already complex class hierarchy