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:
- Subclass the original Component class into a Decorator class (see UML diagram);
- In the Decorator class, add a Component pointer as a field;
- In the Decorator class, pass a Component to the Decorator constructor to initialize the Component pointer;
- In the Decorator class, forward all Component methods to the Component pointer; and
- In the ConcreteDecorator class, override any Component method(s) whose behavior needs to be modified.
Here is best explain video about this design pattern