14-Apr-2022 Engr. Majid Kaleem 1
14-Apr-2022 Engr. Majid Kaleem 1
14-Apr-2022 Engr. Majid Kaleem 1
1
14-Apr-2022
2
14-Apr-2022
3
14-Apr-2022
4
14-Apr-2022
5
14-Apr-2022
6
14-Apr-2022
7
14-Apr-2022
8
14-Apr-2022
9
14-Apr-2022
10
14-Apr-2022
11
14-Apr-2022
12
14-Apr-2022
1. SINGLETON PATTERN
• Purpose:
• There are situations in a project where we want only one instance of the object to be
created and shared between the clients.
• This pattern ensures a class has only one instance and provides a global (app-level) point
of access to it.
• In other words, a class must ensure that only single instance should be created and single
object can be used by all other classes.
• Ensures that at most only one instance of an object exists throughout application and no
client can create an instance of the object from outside.
• Moreover, the object should not be created until it is actually needed.
13
14-Apr-2022
2. BUILDER PATTERN
• Purpose:
• Builder pattern helps us to separate the construction of a complex object from its
representation so that the same construction process can create different representations.
• Builder pattern is useful when the construction of the object is very complex.
• The main objective is to separate the construction of objects and their representations.
• If we are able to separate the construction and representation, we can then get many
representations from the same construction.
14
14-Apr-2022
15
14-Apr-2022
3. PROTOTYPE PATTERN
• Purpose:
• A fully initialized instance to be copied or cloned instead of creating new one and can also
be customized as per the requirement.
• It gives us a way to create new objects from the existing instance of the object.
• In one sentence we clone the existing object with its data.
• By cloning any changes to the cloned object does not affect the original object value.
16
14-Apr-2022
4. FACTORY METHOD
• Purpose:
• Defines an interface or abstract class for creating an object but let the subclasses decide
which class to instantiate.
• In other words, subclasses are responsible to create the instance of the class.
• Factory Method could be used to create objects related to a single family.
• Creates objects of several related classes without specifying the exact object to be
created.
• Factory pattern is meant to centralize the creation of objects.
17
14-Apr-2022
5. ABSTRACT FACTORY
• Purpose:
• The purpose of the Abstract Factory is to provide an interface or abstract class for creating
families or sets of related (or dependent) objects, without specifying concrete sub-classes.
• The Abstract Factory is used when you must coordinate the creation of families or sets of
objects.
• It's also sometimes called a factory of factories.
18
14-Apr-2022
19
14-Apr-2022
20