Skip to content
Sharp

Design patterns · interview question

new BufferedInputStream(new FileInputStream(file)) adds buffering to a stream by wrapping it. Which pattern is this?

Multiple choiceMedium
Choose one answer
Answer and explanation

Correct answer

A. Decorator

Why

A Decorator implements the same interface as the object it wraps and adds behavior, and decorators can be stacked.

References

  • Gamma, Helm, Johnson & Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software (1994)

Test yourself on Design patterns

A free test with instant, explained results. No account needed.

Start free test
All Design patterns questions →