Design Pattern Factory Pattern - Design Patterns

What is Design Pattern Factory Pattern?

Factory pattern is one of the most used design patterns in Java. This type of design pattern come under creational pattern as this pattern provides one of the best ways to build an objective.

In Factory pattern, we build entity without exposing the creation logic to the customer and refer to newly produced object using a universal interface.

Implementation

We're obtainable to create a Shape interface and concrete classes implementing the form interface. A factory class Shape Factory is define as a next step.

FactoryPatternDemo, our presentation class will use Shape Factory to get a Shape article. It will pass information (CIRCLE / RECTANGLE / SQUARE) to form Factory to get the type of entity it needs.
factory_pattern_uml_diagram

Step 1

Create an interface.

Shape.java

Step 2

Make concrete classes implementing the similar interface.

Rectangle.java

Square.java

Circle.java

Step 3

Construct a Factory to create object of concrete class based on given information.

ShapeFactory.java

Step 4

Apply the Factory to get entity of material class by momentary an information such as kind.

FactoryPatternDemo.java

Step 5

Prove the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics