Factory Design Pattern Tutorial

In my previous “Singleton Design Pattern” tutorial we got to know how to create only one instance of a class in the context.
Now we will see how “Factory pattern” works . This design pattern is using in most of the software projects.
This design pattern will explains us how exactly will create an object based on the user’s input. Please have a look in the below code snippet.

Here we are using one inerface called “Bank” which implements two classes ICICIBank and HDFCBank. And we implemented one more class called “BANKFactory” which is responsible to create and provide respective object based on the parameter(ICICI/HDFC) we have passed.




Here getBank() method will return the respective object based on the user input.



Hope you got to know the clear picture on Factory design pattern.

Download  Source Code



Posted in designpatterns and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.