Skip to content
Sharp

Object-oriented programming · interview question

Which design pattern is most closely associated with favoring composition over inheritance?

Multiple choiceMediumchapter-5-curatedpremiumoopcomposition-vs-inheritance
Choose one answer
Answer and explanation

Correct answer

C. Decorator

Why

The Decorator pattern uses composition to add behavior to individual objects dynamically, without affecting the behavior of other objects from the same class.

Test yourself on Object-oriented programming

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

Start free test
All Object-oriented programming questions →