Motivation
- Object creation logic become convoluted
- Constructor is not descriptive
- Name is restricted by name of the container
- Cannot overload name sets of arguments with different names
- Can turn into “optional parameter hell”
- Object creation can be outsourced to
- A separate function
- That may exist in a separate class
- Can create hierarchy of factories with Abstract Factory
Factory Method
- A static method to create objects
Factory
- A factory can take care of object creation entirely
Inner Factory
- An instance of Factory Class inside the modeling Class
- An nested class
Abstract Factory
- Hierarchy of Factory to create related objects
Functional Factory