Skip to content
Sharp

Design patterns · interview question

Why is it important for a context in the Strategy Pattern to use an interface for strategies?

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

Correct answer

B. To allow swapping strategies without modifying the context.

Why

Using an interface allows the context to swap strategies without modifying its code, adhering to the Open/Closed Principle and promoting loose coupling between the context and the strategies.

Test yourself on Design patterns

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

Start free test
All Design patterns questions →