Skip to content
Sharp

Design patterns · interview question

In the context of an e-commerce application, you want to add both gift wrapping and seasonal discounts to the base price of an item without altering the original item class. Which design pattern is most suitable?

Multiple choiceEasychapter-13-curatedpremiumdesign-patternsdecorator-pattern
Choose one answer
Answer and explanation

Correct answer

C. Decorator

Why

The Decorator pattern is ideal for adding additional responsibilities to an object dynamically. It provides a flexible alternative to subclassing for extending functionality.

Test yourself on Design patterns

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

Start free test
All Design patterns questions →