Factory Pattern
The factory pattern encapsulates object creation in factory classes/methods; callers need not know the concrete class and create objects through an interface.
Purpose
Decouple object creation from usage, supporting polymorphic creation and configuration-driven instantiation.
Mechanism
Simple factory: one method creates different objects per argument. Factory method: subclasses decide which object to create. Abstract factory: creates families of related objects. A DI container is a super factory.
Use cases
- Object creation decoupling
- Polymorphic instantiation
- Configuration-driven