This is Decorator
pattern. From Design Patterns book:
Intent: attach additional responsibilities to an object dynamically.
Decorators provide a flexible alternative to subclassing for extending
functionality
...
Applicability: Use Decorator
- to add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects.
- for responsibilities that can be withdrawn.
- when extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an
explosion of subclasses to support every combination. Or a class
definition may be hidden or otherwise unavailable for subclassing.
In case of BufferedReader
, it attaches buffering feature to FileReader
.
If you want to know more about patterns, I recommend reading this book (or more lighter "Head First Patterns"). Additionally, there's brilliant answer on SO about patterns usage inside JDK -- very cool stuff!