Factory Method Pattern
A Factory Pattern or Factory Method Pattern says that just define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate. In other words, subclasses are responsible to create the instance of the class.
The Factory Method Pattern is also known as Virtual Constructor.
Advantage of Factory Design Pattern
Usage of Factory Design Pattern
UML for Factory Method Pattern
Calculate Electricity Bill : A Real World Example of Factory Method
Step 1: Create a Plan abstract class.
Step 2: Create the concrete classes that extends Plan abstract class.
Step 3: Create a GetPlanFactory to generate object of concrete classes based on given information..
Step 4: Generate Bill by using the GetPlanFactory to get the object of concrete classes by passing an information such as type of plan DOMESTICPLAN or COMMERCIALPLAN or INSTITUTIONALPLAN.