Skip to content

Latest commit

 

History

History

decorator

README.md

Name

Decorator Design Pattern

Type

Structural design pattern.

Design Principle

Classes should be open for extension but closed for modification.

About

Decorator pattern allows adding additional behaviors to objects dynamically at runtime without affecting other object of same type by placing them inside wrapper objects. Basically, Attach additional responsibilities to an object dynamically and provide a flexible alternative to subclassing for extending functionality.

JDK Example

InputStream is a Base abstract Class and FilterInputStream is a decorator class extended by child classes like BufferedInputStream.

References

Head First Design Patterns.