Now, we will now get to know the Factory Method Design Pattern.
The Factory Method Pattern gives us a way to encapsulate the instantiations of concrete types. The Factory Method pattern encapsulates the functionality required to select and instantiate an appropriate class, inside a designated method referred to as a factory method. The Factory Method selects an appropriate class from a class hierarchy based on the application context and other influencing factors. It then instantiates the selected class and returns it as an instance of the parent class type.
Via a real life example, you will learn how and when the Factory Method design pattern should be used and how to structure your code in order to implement it. You will see how it can lead to elegant solutions to code problems.