CS FundamentalsHardProduct-company MCQ pattern

Java's I/O library lets you write new BufferedReader(new InputStreamReader(socket.getInputStream())), each wrapper adding behaviour to the object it wraps while keeping a compatible interface. Which pattern is this?

  1. A. Decorator
  2. B. Composite
  3. C. Strategy
  4. D. Chain of Responsibility

Correct answer: A. Decorator

Decorator wraps an object to add responsibilities dynamically, and wrappers can be stacked. Composite builds part-whole trees; Strategy swaps algorithms.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic