Factory Pattern
Noun · Development
Definitions
The Factory pattern is a creational design pattern that delegates object creation to a dedicated method or class rather than using direct constructors. The client specifies a type or parameters, and the factory decides which concrete class to instantiate. This decouples client code from specific classes, making it easy to add new types without modifying existing code (following the Open/Closed Principle). Variants include the Simple Factory (conditional logic in one method), the Factory Method (subclasses override creation), and the Abstract Factory (a family of related factories). Real-world examples include database driver factories that return MySQL or PostgreSQL connections based on configuration, and UI toolkits that produce platform-specific widgets.
In plain English: Using a helper to create objects so your code doesn't need to know which specific class to use.
Example: "The payment factory creates StripePayment, PayPalPayment, or CryptoPayment based on the config — the checkout code never imports concrete classes."