Design patterns – Decorator

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

It is used to allow the functionality to be added/removed to an object without modifying the base class.

Let’s say we have a class called Decorated, and another class that extends it (ExtendedClass)


We can now decorate the object as many times as we want, such as:


The full code can be found at the following link:

You may also like...

Leave a Reply