0% found this document useful (0 votes)
11 views13 pages

Factory DP

The document discusses the Factory Method Design Pattern, a creational pattern that allows subclasses to determine the type of objects created, enhancing flexibility and extensibility. It outlines use cases in various frameworks and libraries, implementation steps including creating a Shape interface and a ShapeFactory, and provides a testing approach. The document serves as a guide for understanding and applying the Factory Method pattern in software development.

Uploaded by

ashfakazad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

Factory DP

The document discusses the Factory Method Design Pattern, a creational pattern that allows subclasses to determine the type of objects created, enhancing flexibility and extensibility. It outlines use cases in various frameworks and libraries, implementation steps including creating a Shape interface and a ShapeFactory, and provides a testing approach. The document serves as a guide for understanding and applying the Factory Method pattern in software development.

Uploaded by

ashfakazad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

DESIGN

PATTERN
Factory Method
1

TEAM MEMBERS
Md. Abdul Muqtadir Rashikh Ahmad
210041203 210041255

Ashfak Azad Nafi Zawad Bin Shoukat (Tasin)


210041245 210041257

Sayad Ibn Azad


Muhammad Asif Rayhan
210041251 210041263
2

OVERVIEW
Introduction
When to use
Use cases
Implementation
Class diagram
Step 1 to 3
Test and result
3

INTRODUCTION

The Factory Method Design Pattern is a creational design pattern


that provides an interface for creating objects in a superclass,
allowing subclasses to alter the type of objects that will be created.
This pattern is particularly useful when the exact types of objects to
be created may vary or need to be determined at runtime, enabling
flexibility and extensibility in object creation.
11

USE CASES

Used in JDBC for creating connections and in frameworks like


Spring for managing beans.

Libraries like Swing and JavaFX use factories to create flexible UI


components.

Tools like Log4j rely on factories to create configurable loggers.

Factories help create objects from serialized data, supporting


various formats.
4

WHEN TO USE

If your object creation Using a factory method can


process is complex or make your client code simpler
varies under different and promote reusability.
conditions

If your application needs Factory Method provides a flexible


way to handle these variations by
to create different defining specific factory methods
versions of a product or for each product type
may introduce new types
in the future
5

IMPLEMENTATION
OVERVIEW

We’re going to create a Shape interface and concrete classes


implementing the shape interface. A factory class ShapeFactory is defined
as a next step.

FactoryPatternDemo, our demo class will use ShapeFactory to get a shape


object. It will pass information (CIRCLE/RECTANGLE/SQUARE) to
ShapeFactory to get the type of object it needs.
6

IMPLEMENTATION
CLASS DIAGRAM

We’re going to implement following class diagram with step by step explaination
7

IMPLEMENTATION
STEP 1 TO 3

Step 1: Create Interface


8

IMPLEMENTATION
STEP 1 TO 3

Step 2: Concrete Classes


9

IMPLEMENTATION
STEP 1 TO 3

Step 3: Shape Factory

To keep the implementation


simple, we can define our factory
class ShapeFactory as shown in
the picture. This will return
appropiate object.
IMPLEMENTATION 10

TEST AND RESULT

TEST
We can easily test our pattern by
just writing this code in our main
function.
First create a shape factory and use
its getShape method in order to
draw new objects.

RESULT
THANK YOU

You might also like