Skip to content
Sharp

Design patterns · interview question

When refactoring a large switch statement in a checkout system, which pattern provides a cleaner solution?

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

Correct answer

B. Strategy Pattern

Why

The Strategy Pattern is well-suited for replacing large switch statements by encapsulating each condition's behavior into its own class, thus allowing for easy extension and maintenance.

Test yourself on Design patterns

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

Start free test
All Design patterns questions →