The factory pattern is a creational pattern that provides a template that can be used to create objects. It is used in complex situations where the type of the object required varies and needs to be specified in each case. it provides a generic interface that delegates the object creation responsibility to the corresponding subclass.
- When the type of objects required cannot be anticipated beforehand
- When you want to provide a generic interface for creating objects
- When you want to hide the creation logic from the client