Professional Documents
Culture Documents
DP Assignment 2 Sol
DP Assignment 2 Sol
Assignment 2
Submitted by:
M Waqas Arif
70067876
Section T
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