[go: up one dir, main page]

0% found this document useful (0 votes)
55 views5 pages

DP Assignment 2 Sol

The factory and abstract factory patterns address design issues by allowing subclasses to choose the type of objects to create and promoting loose coupling. They isolate client code from concrete classes and are used when a class doesn't know what subclasses will be required or when a system needs to be independent of how objects are created. The factory pattern provides a interface for creating products while the abstract factory pattern provides interfaces for creating families of related products.

Uploaded by

Imraan Imraan
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)
55 views5 pages

DP Assignment 2 Sol

The factory and abstract factory patterns address design issues by allowing subclasses to choose the type of objects to create and promoting loose coupling. They isolate client code from concrete classes and are used when a class doesn't know what subclasses will be required or when a system needs to be independent of how objects are created. The factory pattern provides a interface for creating products while the abstract factory pattern provides interfaces for creating families of related products.

Uploaded by

Imraan Imraan
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/ 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