Which pattern adds behavior such as logging or caching around an object without changing the object's class?
Practice this question from Quiz: Design Patterns, with options and an explanation.
Question
Which pattern adds behavior such as logging or caching around an object without changing the object's class?
Option A — Correct answer
Decorator
Decorator composes behavior around an object while preserving the same contract.
Option B
Singleton
Option C
Prototype
Option D
Template Method