Also known as wrapper, is used to extend the functionality of an object dynamically without having to change the original class source or using inheritance. This is accomplished by creating an object wrapper referred to as a Decorator around the actual object.
This wrapping is typically achieved by passing the original object as a parameter to the constructor of the decorator when it is created. The decorator implements the new functionality, but for functionality that is not new, the original (wrapped) class is used. The decorating class must have the same interface as the original class.
The Decorator object adds some additional functionality before or after forwarding requests to the underlying object. This ensures that the additional functionality can be added to a given object externally at runtime without modifying its structure.
Decorator is more flexible than inheritance and works at runtime as opposed to inheritance working at compile time.
public ConcreteDecorator (Structure decoratedStruct) { super(decoratedStruct) } ... Structure decoratedStruct = new ConcreteDecorator(new ConcreteSturcture()); decoratedStruct.addedFunctionality(); //new functionality decoratedStruct.functionality(); //old funtionality






