Design patterns · interview question
Which of the following statements is true regarding the implementation of the Strategy Pattern?
Multiple choiceHardchapter-13-curatedpremiumdesign-patternsstrategy-pattern
Answer and explanation
Correct answer
C. The context class should depend on a strategy interface, not concrete implementations.
Why
In the Strategy Pattern, the context class should be dependent on a generic strategy interface, allowing for different implementations of strategies without knowing the concrete classes, ensuring flexibility and adherence to the Open/Closed Principle.
Test yourself on Design patterns
A free test with instant, explained results. No account needed.
More Design patterns questions
- How can the Strategy Pattern help in reducing the complexity of a checkout system?
- If an e-commerce platform needs to switch between different inventory management algorithms depending on the region,…
- How would you implement a Proxy pattern to control access to a remote service that calculates tax rates in an…
- Which pattern should you use to provide a consistent API for multiple e-commerce payment providers?
- Which of the following is a key characteristic of the Proxy pattern in Java?
- What should a payment adapter own when integrating a vendor SDK?