Factory method
Factory method is categorized under creational design patterns. This design pattern provides an interface for create objects in a super class and allows sub classes to alter the type of objects that will created.
Get Yasara Fernando’s stories in your inbox
Join Medium for free to get updates from this writer.
Ex : Imagine there is a biscuit factory where sells circular shaped biscuits and square shaped biscuit. By using an interface with the common methods of the two types of biscuits we can use this design pattern. Two biscuit classes (concrete classes) can be implemented from the factory interface. Specific methods can be included in concrete classes.
When implementing factory pattern we can use a parameter to determine which instance needed to get. In this pattern we don’t know the instance what we are going to get (sometimes get sub instances instead of parent instances).








