:::: MENU ::::

Factory Design Pattern

Design pattern are generally aimed at solving the problem of Object Oriented Programming of object generation and interaction. Design Patterns are categorized in three groups like:

  • Creational Pattern
  • Structural Pattern
  • Behavioral Pattern

What is factory design pattern ?
Factory design pattern is a creation design pattern, In Factory pattern, we create object without exposing the creation logic. In this pattern, an interface is used for creating an object, but let subclass decide which class to instantiate. The creation of object is done when it is required. The Factory method allows a class later instantiation to subclasses.

Java Project – Factory pattern :

I am using a simple scenario where we try to get the different interest rate for different type of account like saving account, Fixed deposit account and PPF account. But you may introduce the code to use more type of account as per your hands on.

The project Structure should look like this:

factory design pattern

Account Class:

Fixed Account : SubClass Implementing Account Interface

Saving Account : SubClass Implementing Account Interface

PPF Account : SubClass Implementing Account Interface

Account Factory Class:

Client(main) Class :

You can fork/clone the code from GitHub, or you can simple download the project from below link.

Download the Source Code

Download it – Factory Design Pattern
Koushik Ghosh

Koushik Ghosh

Co-founder of CodeStrive. I am a developer in Java. I love coffee, music, coding, open source technology and playing Counter Strike. Feel free to connect me ..
Koushik Ghosh

Latest posts by Koushik Ghosh (see all)

Hands On Java Servlet With Eclipse and Apache Tomcat
Pride that quarells at self-breath