Place variable code in a factory class.
Define an interface for creating an object, but let the subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Principles:
Encapsulate what varies
Program to interfaces not implementations
Open for extension, closed for modification
Depend on abstractions
Factory Pattern is concerned with encapsulating the decision about what type of products to create.
Loose Coupling Principle
Concerned with encapsulating the complexities of how we build an individual object. Separates the construction of a complex object from its representation so that the same construction process can create different representations.
Specify the kinds of objects to create using a prototype instance, and create new objects by copying this prototype.
Create only one instance.