CS FundamentalsHardGATE CS · TCS NQT Prime · Product Company SDE

A logging library needs to let client code add new, optional behaviours (timestamping, compression, encryption) to a basic file writer, in any combination, without creating an explosive number of subclasses for every combination. Which pattern fits?

  1. A. Factory Method pattern
  2. B. Singleton pattern
  3. C. Adapter pattern
  4. D. Decorator pattern

Correct answer: D. Decorator pattern

Decorator wraps an object with additional objects implementing the same interface, letting behaviours be composed and combined at run time instead of needing a subclass for every combination.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic