The Decorator Pattern attaches additional responsibilities to an object dynamically. Decorator provides a flexible alternative to sub-classing for extending functionality.
There are two important parts to the Decorator Pattern:
- Components
- Decorators
There will be one abstract class for the components and all Concrete Components will extend this abstract component class. Also there will be one abstract Decorator class which extents the abstract component class. All concrete decorators will extent abstract Decorator class.
Design Principle: "
Class should be open for extension but closed for modification".
This principle is called
open-closed principle. This is one of the most important design principles.
Java IO libraries are implemented using Decorator Pattern.
No comments:
Post a Comment