SlideShare a Scribd company logo
CS F213 Object Oriented Programming
Design Patterns in Java
Aritra Mukherjee, Dept. of CSIS
Introduction
A design pattern is a generic
repeatable solution to a frequently
occurring problem in software design
that is used in software engineering. It
isn’t a complete design that can be
written in code right away. It is a
description or model for
problem-solving that may be applied
in a variety of contexts.
The Gang of Four
Gang of Four Design Patterns is the collection of 23 design patterns from the book
“Design Patterns: Elements of Reusable Object-Oriented Software”. The authors (L-R)
are: Ralph Johnson, Erich Gamma, Richard Helm and John Vlissides
Types of Design patterns
Creational design patterns are a
subset of design patterns in software
development. They deal with the
process of object creation, trying to
make it more flexible and efficient. It
makes the system independent and
how its objects are created,
composed, and represented.
➔ Factory Method
➔ Abstract Factory Method
➔ Builder Method
➔ Prototype Method
➔ Singleton Method
Types of Design patterns
Structural design patterns are a
subset of design patterns in software
development that focus on the
composition of classes or objects to
form larger, more complex structures.
They help in organizing and managing
relationships between objects to
achieve greater flexibility, reusability,
and maintainability in a software
system.
➔ Adapter Method
➔ Bridge Method
➔ Composite Method
➔ Decorator Method
➔ Facade Method
➔ Proxy Method
➔ Flyweight Method
Types of Design patterns
Behavioral design patterns are a
subset of design patterns in software
development that deal with the
communication and interaction
between objects and classes. They
focus on how objects and classes
collaborate and communicate to
accomplish tasks and responsibilities.
➔ Command Method
➔ Iterator Method
➔ Mediator Method
➔ Memento Method
➔ Observer method
➔ State Method
➔ Strategy Method
➔ Template Method
➔ Visitor Method
➔ Null Object Method
Thank you GFG!
The following slides uses content
from GFG.
The slides are very brief and not at all
comprehensive
Try to understand the concepts, don’t
just memorize the slides!
Factory
The Factory Method Design Pattern is a
creational design pattern that provides an
interface for creating objects in a superclass,
allowing subclasses to alter the type of
objects that will be created.
It encapsulates object creation logic in a
separate method, promoting loose coupling
between the creator and the created objects.
This pattern is particularly useful when the
exact types of objects to be created may
vary or need to be determined at runtime,
enabling flexibility and extensibility in object
creation.
Abstract Factory
The Abstract Factory Pattern
is a creational design pattern
that provides an interface for
creating families of related or
dependent objects without
specifying their concrete
classes,
In simpler terms the Abstract
Factory Pattern is a way of
organizing how you create
groups of things that are
related to each other.
Singleton
The Singleton method or Singleton
Design pattern is one of the simplest
design patterns. It ensures a class only
has one instance, and provides a global
point of access to it.
● There must be exactly one instance
of a class and it must be accessible
to clients from a well-known access
point.
● When the sole instance should be
extensible by subclassing and
clients should be able to use an
extended instance without
modifying
● Singleton classes are used for
logging, driver objects, caching, and
thread pool, database connections.
Builder
The Builder Design Pattern is a
creational pattern used in software
design to construct a complex object
step by step.
It allows the construction of a product
in a step-by-step fashion, where the
construction process can vary based
on the type of product being built.
The pattern separates the
construction of a complex object
from its representation, allowing the
same construction process to create
different representations.
Prototype
The Prototype Design Pattern is a
creational pattern that enables the
creation of new objects by copying an
existing object.
Prototype allows us to hide the
complexity of making new instances
from the client. The concept is to
copy an existing object rather than
create a new instance from scratch,
something that may include costly
operations.
The existing object acts as a
prototype and contains the state of
the object.
Adapter
The Adapter design pattern is a
structural pattern that allows the
interface of an existing class to be
used as another interface.
It acts as a bridge between two
incompatible interfaces, making
them work together.
This pattern involves a single class,
known as the adapter, which is
responsible for joining functionalities
of independent or incompatible
interfaces.
Bridge
The Bridge design pattern allows you
to separate the abstraction from the
implementation. It is a structural
design pattern.
The bridge pattern allows the
Abstraction and the Implementation
to be developed independently
The abstraction is an interface or
abstract class and the implementer is
also an interface or abstract class.
The abstraction contains a reference
to the implementer.
Composite
The Composite Design Pattern is a structural
design pattern that lets you compose objects into
tree-like structures to represent part-whole
hierarchies. It allows clients to treat individual
objects and compositions of objects uniformly.
In other words, whether dealing with a single
object or a group of objects (composite), clients
can use them interchangeably.
As described by the Gang of four, “Compose
objects into tree structure to represent part-whole
hierarchies. Composite lets client treat individual
objects and compositions of objects uniformly”.
Decorator
The Decorator Design Pattern is a structural design
pattern that allows behavior to be added to individual
objects dynamically, without affecting the behavior of
other objects from the same class.
It involves creating a set of decorator classes that are
used to wrap concrete components.
Suppose we are building a coffee shop application
where customers can order different types of coffee.
Each coffee can have various optional add-ons such
as milk, sugar, whipped cream, etc. We want to
implement a system where we can dynamically add
these add-ons to a coffee order without modifying
the coffee classes themselves.
Facade
Facade Method Design
Pattern provides a
unified interface to a
set of interfaces in a
subsystem. Facade
defines a high-level
interface that makes
the subsystem easier to
use.
Proxy
The Proxy Design Pattern
is a structural design
pattern that provides a
surrogate or placeholder
for another object to
control access to it.
This pattern is useful
when you want to add an
extra layer of control over
access to an object. The
proxy acts as an
intermediary, controlling
access to the real object.
Flyweight
Flyweight pattern is one of the
structural design patterns as this
pattern provides ways to
decrease object count thus
improving application required
objects structure.
One important feature of
flyweight objects is that they are
immutable. This means that they
cannot be modified once they
have been constructed.
Command
The Command Design
Pattern is a behavioral
design pattern that turns a
request into a stand-alone
object, allowing
parameterization of clients
with different requests,
queuing of requests, and
support for undoable
operations(action or a
series of actions that can
be reversed or undone in a
system).
Iterator
The iterator pattern is a great
pattern for providing
navigation without exposing
the structure of an object.
It is an interface-based design
pattern. Whichever object you
want to iterate over will
provide a method to return an
instance of an iterator from it.
Follows a factory-based
method pattern in the way you
get an instance of the iterator.
Mediator
The Mediator design pattern is a
behavioral pattern that defines an
object, the mediator, to centralize
communication between various
components or objects in a
system.
This promotes loose coupling by
preventing direct interactions
between components, instead of
having them communicate
through the mediator, facilitating
better maintainability and
flexibility in the system
architecture.
Memento (interpreter)
The Memento design pattern
is a behavioral design pattern
used to capture and restore
the internal state of an object
without exposing its
implementation details.
The intent of the Memento
Design pattern is without
violating encapsulation, to
capture and externalize an
object’s internal state so that
the object can be restored to
this state later.
Observer
The Observer Design
Pattern is a behavioral
design pattern that
defines a one-to-many
dependency between
objects so that when one
object (the subject)
changes state, all its
dependents (observers)
are notified and updated
automatically.
State
The State design pattern is
a behavioral software
design pattern that allows
an object to alter its
behavior when its internal
state changes.
It achieves this by
encapsulating the object’s
behavior within different
state objects, and the object
itself dynamically switches
between these state objects
depending on its current
state.
Strategy
The Strategy Design Pattern
defines a family of
algorithms, encapsulates
each one, and makes them
interchangeable, allowing
clients to switch algorithms
dynamically without altering
the code structure.
The Strategy Pattern allows
you to define a family of
algorithms, encapsulate
each one of them, and make
them interchangeable.
Template
The Template Method
design pattern is a
behavioral design pattern
that defines the skeleton of
an algorithm in a superclass
but allows subclasses to
override specific steps of
the algorithm without
changing its structure.
It promotes code reuse by
encapsulating also enabling
customization and
flexibility.
Visitor
Visitor design pattern is one of
the behavioral design patterns. It
is used when we have to perform
an operation on a group of similar
kind of Objects. With the help of
visitor pattern, we can move the
operational logic from the objects
to another class.
a method called Visit() which is
implemented by the visitor and is
called for every element in the
data structure
visitable classes providing
Accept() methods that accept a
visitor
Null Object
The Null Object Design
Pattern is a behavioral
design pattern that is used
to provide a consistent way
of handling null or
non-existing objects.
It is particularly useful in
situations where you want
to avoid explicit null checks
and provide a default
behavior for objects that
may not exist.
Differences between design patterns
Creational Patterns vs. Structural Patterns: Creational patterns focus on object
creation, while structural patterns deal with object composition.
Structural Patterns vs. Behavioral Patterns: Structural patterns focus on
defining the structure of objects, while behavioral patterns are concerned with
how objects interact.
Creational Patterns vs. Behavioral Patterns: Creational patterns are concerned
with object creation, while behavioral patterns deal with the interaction between
objects.

More Related Content

Similar to Design Patterns Java programming language.pdf (20)

Oops design pattern_amitgupta
Oops design pattern_amitguptaOops design pattern_amitgupta
Oops design pattern_amitgupta
Amit Gupta, MCSD TOGAF
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Rafael Coutinho
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Sergii Stets
 
ap assignmnet presentation.pptx
ap assignmnet presentation.pptxap assignmnet presentation.pptx
ap assignmnet presentation.pptx
AwanAdhikari
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
Satheesh Sukumaran
 
Design pattern
Design patternDesign pattern
Design pattern
Ramakrishna kapa
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
Anil Sharma
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive
 
Module 4: UML In Action - Design Patterns
Module 4:  UML In Action - Design PatternsModule 4:  UML In Action - Design Patterns
Module 4: UML In Action - Design Patterns
jaden65832
 
Software Design Patterns - An Overview
Software Design Patterns - An OverviewSoftware Design Patterns - An Overview
Software Design Patterns - An Overview
Farwa Ansari
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Knoldus Inc.
 
OOP design patterns
OOP design patternsOOP design patterns
OOP design patterns
Igor Talevski
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
Miriam Ruiz
 
M04_DesignPatterns software engineering.ppt
M04_DesignPatterns software engineering.pptM04_DesignPatterns software engineering.ppt
M04_DesignPatterns software engineering.ppt
ssuser2d043c
 
Design pattern
Design patternDesign pattern
Design pattern
Mallikarjuna G D
 
Design Pattern - Introduction
Design Pattern - IntroductionDesign Pattern - Introduction
Design Pattern - Introduction
Mudasir Qazi
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
Mindfire Solutions
 
ap assignmnet presentation.pptx
ap assignmnet presentation.pptxap assignmnet presentation.pptx
ap assignmnet presentation.pptx
AwanAdhikari
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
dotnet stuff.com tutorials-design-patterns_exploring-net-design-patterns-in-s...
Anil Sharma
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive
 
Module 4: UML In Action - Design Patterns
Module 4:  UML In Action - Design PatternsModule 4:  UML In Action - Design Patterns
Module 4: UML In Action - Design Patterns
jaden65832
 
Software Design Patterns - An Overview
Software Design Patterns - An OverviewSoftware Design Patterns - An Overview
Software Design Patterns - An Overview
Farwa Ansari
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
Miriam Ruiz
 
M04_DesignPatterns software engineering.ppt
M04_DesignPatterns software engineering.pptM04_DesignPatterns software engineering.ppt
M04_DesignPatterns software engineering.ppt
ssuser2d043c
 
Design Pattern - Introduction
Design Pattern - IntroductionDesign Pattern - Introduction
Design Pattern - Introduction
Mudasir Qazi
 

Recently uploaded (20)

AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
dp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdfdp-700 exam questions sample docume .pdf
dp-700 exam questions sample docume .pdf
pravkumarbiz
 
Code and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage OverlookCode and No-Code Journeys: The Coverage Overlook
Code and No-Code Journeys: The Coverage Overlook
Applitools
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Software Testing & it’s types (DevOps)
Software  Testing & it’s  types (DevOps)Software  Testing & it’s  types (DevOps)
Software Testing & it’s types (DevOps)
S Pranav (Deepu)
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025FME as an Orchestration Tool - Peak of Data & AI 2025
FME as an Orchestration Tool - Peak of Data & AI 2025
Safe Software
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
OpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native BarcelonaOpenTelemetry 101 Cloud Native Barcelona
OpenTelemetry 101 Cloud Native Barcelona
Imma Valls Bernaus
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
Integrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FMEIntegrating Survey123 and R&H Data Using FME
Integrating Survey123 and R&H Data Using FME
Safe Software
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The SequelMarketo & Dynamics can be Most Excellent to Each Other – The Sequel
Marketo & Dynamics can be Most Excellent to Each Other – The Sequel
BradBedford3
 
Ad

Design Patterns Java programming language.pdf

  • 1. CS F213 Object Oriented Programming Design Patterns in Java Aritra Mukherjee, Dept. of CSIS
  • 2. Introduction A design pattern is a generic repeatable solution to a frequently occurring problem in software design that is used in software engineering. It isn’t a complete design that can be written in code right away. It is a description or model for problem-solving that may be applied in a variety of contexts.
  • 3. The Gang of Four Gang of Four Design Patterns is the collection of 23 design patterns from the book “Design Patterns: Elements of Reusable Object-Oriented Software”. The authors (L-R) are: Ralph Johnson, Erich Gamma, Richard Helm and John Vlissides
  • 4. Types of Design patterns Creational design patterns are a subset of design patterns in software development. They deal with the process of object creation, trying to make it more flexible and efficient. It makes the system independent and how its objects are created, composed, and represented. ➔ Factory Method ➔ Abstract Factory Method ➔ Builder Method ➔ Prototype Method ➔ Singleton Method
  • 5. Types of Design patterns Structural design patterns are a subset of design patterns in software development that focus on the composition of classes or objects to form larger, more complex structures. They help in organizing and managing relationships between objects to achieve greater flexibility, reusability, and maintainability in a software system. ➔ Adapter Method ➔ Bridge Method ➔ Composite Method ➔ Decorator Method ➔ Facade Method ➔ Proxy Method ➔ Flyweight Method
  • 6. Types of Design patterns Behavioral design patterns are a subset of design patterns in software development that deal with the communication and interaction between objects and classes. They focus on how objects and classes collaborate and communicate to accomplish tasks and responsibilities. ➔ Command Method ➔ Iterator Method ➔ Mediator Method ➔ Memento Method ➔ Observer method ➔ State Method ➔ Strategy Method ➔ Template Method ➔ Visitor Method ➔ Null Object Method
  • 7. Thank you GFG! The following slides uses content from GFG. The slides are very brief and not at all comprehensive Try to understand the concepts, don’t just memorize the slides!
  • 8. Factory The Factory Method Design Pattern is a creational design pattern that provides an interface for creating objects in a superclass, allowing subclasses to alter the type of objects that will be created. It encapsulates object creation logic in a separate method, promoting loose coupling between the creator and the created objects. This pattern is particularly useful when the exact types of objects to be created may vary or need to be determined at runtime, enabling flexibility and extensibility in object creation.
  • 9. Abstract Factory The Abstract Factory Pattern is a creational design pattern that provides an interface for creating families of related or dependent objects without specifying their concrete classes, In simpler terms the Abstract Factory Pattern is a way of organizing how you create groups of things that are related to each other.
  • 10. Singleton The Singleton method or Singleton Design pattern is one of the simplest design patterns. It ensures a class only has one instance, and provides a global point of access to it. ● There must be exactly one instance of a class and it must be accessible to clients from a well-known access point. ● When the sole instance should be extensible by subclassing and clients should be able to use an extended instance without modifying ● Singleton classes are used for logging, driver objects, caching, and thread pool, database connections.
  • 11. Builder The Builder Design Pattern is a creational pattern used in software design to construct a complex object step by step. It allows the construction of a product in a step-by-step fashion, where the construction process can vary based on the type of product being built. The pattern separates the construction of a complex object from its representation, allowing the same construction process to create different representations.
  • 12. Prototype The Prototype Design Pattern is a creational pattern that enables the creation of new objects by copying an existing object. Prototype allows us to hide the complexity of making new instances from the client. The concept is to copy an existing object rather than create a new instance from scratch, something that may include costly operations. The existing object acts as a prototype and contains the state of the object.
  • 13. Adapter The Adapter design pattern is a structural pattern that allows the interface of an existing class to be used as another interface. It acts as a bridge between two incompatible interfaces, making them work together. This pattern involves a single class, known as the adapter, which is responsible for joining functionalities of independent or incompatible interfaces.
  • 14. Bridge The Bridge design pattern allows you to separate the abstraction from the implementation. It is a structural design pattern. The bridge pattern allows the Abstraction and the Implementation to be developed independently The abstraction is an interface or abstract class and the implementer is also an interface or abstract class. The abstraction contains a reference to the implementer.
  • 15. Composite The Composite Design Pattern is a structural design pattern that lets you compose objects into tree-like structures to represent part-whole hierarchies. It allows clients to treat individual objects and compositions of objects uniformly. In other words, whether dealing with a single object or a group of objects (composite), clients can use them interchangeably. As described by the Gang of four, “Compose objects into tree structure to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly”.
  • 16. Decorator The Decorator Design Pattern is a structural design pattern that allows behavior to be added to individual objects dynamically, without affecting the behavior of other objects from the same class. It involves creating a set of decorator classes that are used to wrap concrete components. Suppose we are building a coffee shop application where customers can order different types of coffee. Each coffee can have various optional add-ons such as milk, sugar, whipped cream, etc. We want to implement a system where we can dynamically add these add-ons to a coffee order without modifying the coffee classes themselves.
  • 17. Facade Facade Method Design Pattern provides a unified interface to a set of interfaces in a subsystem. Facade defines a high-level interface that makes the subsystem easier to use.
  • 18. Proxy The Proxy Design Pattern is a structural design pattern that provides a surrogate or placeholder for another object to control access to it. This pattern is useful when you want to add an extra layer of control over access to an object. The proxy acts as an intermediary, controlling access to the real object.
  • 19. Flyweight Flyweight pattern is one of the structural design patterns as this pattern provides ways to decrease object count thus improving application required objects structure. One important feature of flyweight objects is that they are immutable. This means that they cannot be modified once they have been constructed.
  • 20. Command The Command Design Pattern is a behavioral design pattern that turns a request into a stand-alone object, allowing parameterization of clients with different requests, queuing of requests, and support for undoable operations(action or a series of actions that can be reversed or undone in a system).
  • 21. Iterator The iterator pattern is a great pattern for providing navigation without exposing the structure of an object. It is an interface-based design pattern. Whichever object you want to iterate over will provide a method to return an instance of an iterator from it. Follows a factory-based method pattern in the way you get an instance of the iterator.
  • 22. Mediator The Mediator design pattern is a behavioral pattern that defines an object, the mediator, to centralize communication between various components or objects in a system. This promotes loose coupling by preventing direct interactions between components, instead of having them communicate through the mediator, facilitating better maintainability and flexibility in the system architecture.
  • 23. Memento (interpreter) The Memento design pattern is a behavioral design pattern used to capture and restore the internal state of an object without exposing its implementation details. The intent of the Memento Design pattern is without violating encapsulation, to capture and externalize an object’s internal state so that the object can be restored to this state later.
  • 24. Observer The Observer Design Pattern is a behavioral design pattern that defines a one-to-many dependency between objects so that when one object (the subject) changes state, all its dependents (observers) are notified and updated automatically.
  • 25. State The State design pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. It achieves this by encapsulating the object’s behavior within different state objects, and the object itself dynamically switches between these state objects depending on its current state.
  • 26. Strategy The Strategy Design Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable, allowing clients to switch algorithms dynamically without altering the code structure. The Strategy Pattern allows you to define a family of algorithms, encapsulate each one of them, and make them interchangeable.
  • 27. Template The Template Method design pattern is a behavioral design pattern that defines the skeleton of an algorithm in a superclass but allows subclasses to override specific steps of the algorithm without changing its structure. It promotes code reuse by encapsulating also enabling customization and flexibility.
  • 28. Visitor Visitor design pattern is one of the behavioral design patterns. It is used when we have to perform an operation on a group of similar kind of Objects. With the help of visitor pattern, we can move the operational logic from the objects to another class. a method called Visit() which is implemented by the visitor and is called for every element in the data structure visitable classes providing Accept() methods that accept a visitor
  • 29. Null Object The Null Object Design Pattern is a behavioral design pattern that is used to provide a consistent way of handling null or non-existing objects. It is particularly useful in situations where you want to avoid explicit null checks and provide a default behavior for objects that may not exist.
  • 30. Differences between design patterns Creational Patterns vs. Structural Patterns: Creational patterns focus on object creation, while structural patterns deal with object composition. Structural Patterns vs. Behavioral Patterns: Structural patterns focus on defining the structure of objects, while behavioral patterns are concerned with how objects interact. Creational Patterns vs. Behavioral Patterns: Creational patterns are concerned with object creation, while behavioral patterns deal with the interaction between objects.