← All Quizzes
What is the Factory pattern and when is it useful?
Explanation
The Factory pattern is a creational design pattern that abstracts object creation, encapsulating the logic for creating objects. It is useful when: object creation is complex, the exact type to create is determined at runtime, you want to centralize creation logic, or you need to hide concrete types from clients. Variants include Simple Factory, Factory Method, and Abstract Factory. Factories improve decoupling, testability (easy to mock), and consistency. They are widely used in frameworks, ORMs, and libraries.