You need to add logging around an existing service without editing that service class. Which pattern is most appropriate?

Practice this question from Quiz: Design Patterns, with options and an explanation.

Question

You need to add logging around an existing service without editing that service class. Which pattern is most appropriate?

Option A — Correct answer

Decorator

Decorator composes extra behavior around the existing service.

Option B

Singleton

Option C

Factory Method

Option D

Enum

Explanation

Decorator adds behavior around an object through composition while preserving the same contract.

Quiz: Design Patterns

All questions · Previous question

Open on QuizMaker