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

FactoryPattern.zip

 

Posted in designpatterns and tagged , .

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">