Skip to content
Sharp

Design patterns · interview question

In a checkout system, you need to apply multiple discounts. Which pattern helps avoid creating numerous subclasses for each combination of discounts?

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

Correct answer

B. Decorator

Why

The Decorator pattern helps you apply multiple layers of functionality without creating a subclass for each combination. It allows different discount behaviors to be added dynamically.

Test yourself on Design patterns

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

Start free test
All Design patterns questions →