Decorator Design Pattern with an Example
Definition:
Attach additional responsibilities or functions to an object dynamically or statically. Also known as Wrapper.
Where to use & benefits:
Read more..
Attach additional responsibilities or functions to an object dynamically or statically. Also known as Wrapper.
Where to use & benefits:
- Provide an alternative to subclassing.
- Add new function to an object without affecting other objects.
- Make a responsibility easily added and removed dynamically.
- More flexibility than static inheritance.
- Transparent to the object.
- Related patterns include
- Adapter pattern, which provides a different interface to the object it adapts, whereas a decorator changes an object's responsibilities,
