Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

DESIGN PATTERN

Assignment 2

Submitted by:
M Waqas Arif
70067876
Section T

MARCH 25, 2021


UNIVERSITY OF LAHORE
Question:
Factory and abstract factory patterns have a very inter related approach to
address particular design issues.

- What design issues does both of these pattern’s address?


- Draw a UML skeleton diagram for each of the pattern.
- Elaborate an example of each design pattern with the help of UML diagrams.

Solution:

• Factory Pattern and Abstract Factory Pattern allows the subclasses to choose the type of
objects to create.
• They promote the loose-coupling by eliminating the need to bind application specific classes
into the code. That means the code interacts solely with the resultant interface or abstract class,
so that it will work with any classes that implement that interface.
• They isolate the client code from concrete classes.
• It is used when a class doesn't know what sub-classes will be required to create or when a class
wants that its subclasses specify the objects to be created or when the system needs to be
independent of how its object are created, composed, and represented or when the family of
related objects has to be used together.
Factory pattern

Product Creator

Function product
create
product ()

Concrete
Product Concrete
creator

Function
product
create
product ()
Abstract factory pattern :
Abstract product Alpha Abstract product beta

Concrete product alpha 1 Concrete product alpha 2 Concrete product beta 1 Concrete product beta 1

Concreate factory 1 Abstract factory Concreate factory 2

Create product alpha() Create product alpha() Create product alpha()


Create product beta() Create product beta() Create product beta()
Factory pattern:
Abstract factory pattern:

You might also like