Design patterns · interview question
How does the Factory Pattern align with the Dependency Inversion Principle?
Multiple choiceMediumchapter-13-curatedpremiumdesign-patternsfactory-pattern
Answer and explanation
Correct answer
C. By abstracting the object creation, it allows high-level modules to depend on abstractions.
Why
The Factory Pattern abstracts the creation of objects, allowing high-level modules to depend on interfaces or abstract classes rather than concrete implementations, thus supporting the Dependency Inversion Principle.
Test yourself on Design patterns
A free test with instant, explained results. No account needed.
More Design patterns questions
- Which principle is most closely aligned with the Factory Pattern?
- Which scenario is least suited for the Decorator pattern?
- Why is it important for a decorator to share the same interface as the object it decorates?
- In an e-commerce application, you want to delay loading product images until they are actually needed. Which design…
- You are designing a system with multiple types of notifications (email, SMS, push). How can the Factory Pattern help…
- Which situation is the clearest example of over-engineering with the Strategy Pattern?