About Decorator design pattern

Decorator design pattern allows the behaviour to be added to an individual object, either statically or dynamically, without affecting the behaviour of other objects from the same class.

It allows functionality to be divided between classes with unique areas of concern

This wrapping could be achieved by the following sequence of steps:

  1. Subclass the original Component class into a Decorator class (see UML diagram);
  2. In the Decorator class, add a Component pointer as a field;
  3. In the Decorator class, pass a Component to the Decorator constructor to initialize the Component pointer;
  4. In the Decorator class, forward all Component methods to the Component pointer; and
  5. In the ConcreteDecorator class, override any Component method(s) whose behavior needs to be modified.
Decorator design pattern uml
Decorator design pattern uml

Here is best explain video about this design pattern