Q1) What are the types of Design Pattern?
Design patterns are categorized into three main types based on their purpose and usage in software
design. These types are Creational Patterns, Structural Patterns, and Behavioral Patterns.
1. Creational Design Patterns
These patterns deal with the creation of objects, focusing on the best way to instantiate objects in
a manner that is scalable, flexible, and efficient.
Ex – Singleton, Factory Method, Builder, etc.
2. Structural Design Patterns
These patterns focus on composing classes and objects into larger structures while keeping them
efficient and flexible.
Ex- Adapter, Decorator, etc.
3. Behavioral Design Patterns
These patterns focus on communication and interaction between objects, ensuring loose coupling
and efficient behavior.
Ex- Iterator, Mediator etc
Q1)Explain Factory Design Pattern
When there is a superclass and multiple subclass and we want to create
an object of the subclass based on the input and requirements.
Then we create a factory class which takes the responsibility of creating
object of subclass based on the input
A Factory Pattern or Factory Method Pattern says that just define 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.
in that case we use a factory design pattern
Advantages of Factory Design Pattern
o Factory Method Pattern allows the sub-classes to choose the type of
objects to create.
o Focusing on creating an object for interface rather than
implementation
o It promotes 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 or that
extends that abstract class.
Usage of Factory Design Pattern
o When a class doesn't know what sub-classes will be required to create
o When a class wants that its sub-classes specify the objects to be
created.
o When the parent classes choose the creation of objects to its sub-
classes.
Example:
[Link]
[Link]
Q)Builder Design Pattern
[Link]
7CKnayxHJA_1ol&index=4
[Link]
7CKnayxHJA_1ol&index=5
Q)Singleton Design Pattern
[Link]
telesko series also if want to refer
[Link]