SDA-7 lecture for algorithm
SDA-7 lecture for algorithm
GOF Design
Patterns
Creational Design
Pattern
Abstract Factory
Factory Method
Method
Factory Pattern
• Factory pattern is one of most used design pattern in
Java.
• This type of design pattern comes under creational
pattern as this pattern provides one of the best ways to
create an object.
• In Factory pattern,
• we create object without exposing the creation logic to the client
and
• refer to newly created object using a common interface.
Implementation
• 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.
Step 1: Create an interface
14
Step 2: Create concrete classes
implementing the same interface
15
Step 3: Create a Factory to generate object of
concrete class based on given information.
16
Step 4: Use the Factory to get object of
concrete class by passing an information such as
type
17
Step 4: Verify the output
18
Practical Use of Factory Pattern
22
Step 1: Create an interface for Shapes
23
Step 2:
Create concrete classes implementing the same interface
24
Step 3+4:
Create an interface for Colours + Implementation classes
25
Step 5: Create an Abstract class to get factories for
Colour and Shape Objects
26
Step 6: Create Factory classes extending Abstract
Factory to generate object of concrete class based on given
information
27
Step 6: Create Factory classes extending Abstract
Factory to generate object of concrete class based on given
information
28
Step 7: Create a Factory generator/producer class to get
factories by passing an information such as Shape or Color
29
Step 8: Use the FactoryProducer to get AbstractFactory in
order to get factories of concrete classes by passing an
information such as type.
30
Step 9: Verify the output
Behavioral Design Pattern
Behavioral
Design Pattern
Strategy Observer
Design Pattern Design Pattern
Summary
• Introduction to Design Pattern
• Importance of Design Patterns
• Design Problems
• Elements of Design Patterns
• Design Pattern Types
• Creational Design Pattern
• Factory Pattern
• Abstract Factory Pattern
• Introduction to Behavioral Design Pattern
Thank You!