SlideShare a Scribd company logo
Design patterns are known as best practices that the programmer can use to solve common problems when designing an
application or system.
Classification of Design Patterns
Creational
Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of
existing code.
Structural
Structural patterns explain how to assemble objects and classes into larger structures while keeping these
structures flexible and efficient.
Behavioral
Behavioral patterns take care of effective communication and the assignment of responsibilities between
objects.
Singleton Design Pattern
Creational(1/4)
Is a creational design pattern that lets you ensure
that a class has only one instance, while providing
a global access point to this instance.
A Singleton encapsulates a unique resource and
makes it readily available throughout the
application
Singleton Design Pattern
Creational(1/4)
When we use it ?
- When a class in your program should have just a single
instance available to all clients; for example, a single
database object shared by different parts of the program.
-Similarly, there can be a single configuration manager or
error manager in an application that handles all problems
instead of creating multiple managers.
-Centralise logging staff
Singleton Design Pattern
Creational(1/4)
Bad things?
-Create a dependance for other classes who create the
instance
-Classes that depend on singletons are relatively harder
to unit test in isolation.Directly impacting testability and
maintainability
-The Singleton design pattern promotes tight coupling
between the classes in your application
The pattern requires special treatment in a
multithreaded environment so that multiple threads
won’t create a singleton object several times.
Singleton Design Pattern
Creational(1/4)
Example
Singleton Design Pattern
Factory Design Pattern
Creational(2/4)
Factory is a creational design pattern that provides an
interface for creating objects in a superclass, but allows
subclasses to alter the type of objects that will be created.
-Allows the consumer to create new objects without having
to know the details of how they're created, or what their
dependencies are -. they only have to give the information
they actually want.
Factory Design Pattern
Creational(2/4)
When we use it ?
- You don’t know beforehand the exact types and
dependencies of the objects your code should work with.
-Construction is very complex and you need to reuse it.
- You want to save system resources by reusing existing
objects instead of rebuilding them each time.
Factory Design Pattern
Creational(2/4)
When NOT use it ?
- We don’t have any complex creation logic.
if the factory doesn’t make any decision, the creation logic
is very simple or is used only in a single place, the factory
will be a needless abstraction.
Factory Design Pattern
Creational(2/4)
Example
Builder Design Pattern Creational(3/4)
Builder pattern builds a complex object using simple objects
and using a step by step approach.The pattern allows you to
produce different types and representations of an object
using the same construction code.
This builder is independent of other objects.
Builder Design Pattern Creational(3/4)
When we use it ?
-When you want your code to be able to create different
representations of some product.
-When you want isolate complex construction code from the
business logic of the product.
Builder Design Pattern Creational(3/4)
Example
Prototype Design Pattern
Creational(4/4)
Prototype is a creational design pattern that lets you copy
existing objects without making your code dependent on
their classes.
Prototype Design Pattern
Creational(4/4)
When we use it ?
-when creation of object directly is costly (heavy process).
For example, an object is to be created after a costly
database operation. We can cache the object, returns its
clone on next request and update the database as and when
needed thus reducing database calls.
Your code shouldn’t depend on the concrete classes of
objects that you need to copy.
Prototype Design Pattern
Creational(4/4)
Example
Decorator Design Pattern Structural(1/3)
Decorator is a structural design pattern that lets you attach
new behaviors to objects by placing these objects inside
special wrapper objects that contain the behaviors.
The decorator pattern allows a user to add new functionality
to an existing object without altering its structure.
Decorator Design Pattern Structural(1/3)
When we use it ?
-When you need to be able to assign extra behaviors to
objects at runtime without breaking the code that uses these
objects.
-When it’s difficult or not possible to extend an object’s
behavior using inheritance.
Decorator Design Pattern Structural(1/3)
Example
Proxy Design Pattern Structural(2/3)
Proxy is a structural design pattern that lets you provide a
substitute or placeholder for another object.
A proxy controls access to the original object, allowing
you to perform something either before or after the
request gets through to the original object.
The proxy could interface to anything: a network
connection, a large object in memory, a file, or some other
resource that is expensive or impossible to duplicate
Proxy Design Pattern Structural(2/3)
When we use it (1/2) ?
you want only specific clients to be able to use the
service object; for instance, when your objects are central
parts of an operating system and clients are various
launched applications (including malicious ones).
The proxy can pass the request to the service object only
if the client’s credentials match some criteria.(control
proxy)
Logging requests (logging proxy). This is when you want
to keep a history of requests to the service object.
The proxy can log each request before passing it to the
service.
Proxy Design Pattern Structural(2/3)
When we use it (2/2) ?
Caching request results (caching proxy). This is when you
need to cache results of client requests and manage the
life cycle of this cache, especially if results are quite large.
The proxy can implement caching for recurring requests
that always generate the same results
Proxy Design Pattern Structural(2/3)
Example
Adapter Design Pattern Structural(3/3)
Adapter is a structural design pattern that allows objects with
incompatible interfaces to collaborate.
This pattern involves a single class which is responsible to join
functionalities of independent or incompatible interfaces.
The Adapter pattern lets you create a middle-layer class that
serves as a translator between your code and a legacy class, a
3rd-party class or any other class with a weird interface.
Adapter Design Pattern Structural(3/3)
When we use it ?
-Use the Adapter class when you want to use some existing
class, but its interface isn’t compatible with the rest of your
code.
-Use the pattern when you want to reuse several existing
subclasses that lack some functionality that can’t be added to
the superclass.
-
Adapter Design Pattern Structural(3/3)
Example
Iterator Design Pattern
Behavioral(1/4)
This pattern is used to get a way to access the elements of a
collection object in a sequential manner without any need to know
its underlying representation. (list, stack, tree, complex data
structures.).
As name implies, iterator helps in traversing the collection of objects
in a defined manner which is useful the client applications.
Iterator Design Pattern
Behavioral(1/4)
When we use it ?
-when your collection has a complex data structure under the hood,
but you want to hide its complexity from clients (either for
convenience or security reasons).
-when you want your code to be able to traverse different data
structures or when types of these structures are unknown
beforehand.
Iterator Design Pattern
Behavioral(1/4)
Example
Observer Design Pattern Behavioral(2/4)
Observer is a behavioral design pattern that lets you define a
subscription mechanism to notify multiple objects about any events
that happen to the object they’re observing.
Observer Design Pattern Behavioral(2/4)
When we use it ?
-When some objects in your app must observe others, but only for a
limited time or in specific cases.
-When changes to the state of one object may require changing
other objects, and the actual set of objects is unknown beforehand or
changes dynamically.
Observer Design Pattern Behavioral(2/4)
Example
Command Design Pattern Behavioral(3/4)
Command is a behavioral design pattern that turns a
request into a stand-alone object that contains all
information about the request. This transformation lets
you parameterize methods with different requests, delay
or queue a request’s execution, and support undoable
operations.
Command Design Pattern Behavioral(3/4)
-When you want to queue operations, schedule their
execution, or execute them remotely.
-when you want to implement reversible operations.
(undo/redo, the Command pattern is perhaps the most
popular of all.)
-Use the Command pattern when you want to parametrize
objects with operations.
( you can pass commands as method arguments, store
them inside other objects, switch linked commands at
runtime, etc.)
Command Design Pattern Behavioral(3/4)
Example
Strategy Design Pattern Behavioral (4/4)
Strategy is a behavioral design pattern that lets you
define a family of algorithms, put each of them into a
separate class, and make their objects
interchangeable.
Strategy Design Pattern Behavioral (4/4)
When we use it ?
-you want to use different variants of an algorithm
within an object and be able to switch from one
algorithm to another during runtime.
-you have a lot of similar classes that only differ in
the way they execute some behavior.
Strategy Design Pattern Behavioral (4/4)
Example

More Related Content

Similar to designpatterns-.pdf

Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Luis Valencia
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
SHAHZAIBABBAS13
 
ap assignmnet presentation.pptx
ap assignmnet presentation.pptxap assignmnet presentation.pptx
ap assignmnet presentation.pptx
AwanAdhikari
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
Miriam Ruiz
 
Design Pattern in Software Engineering
Design Pattern in Software Engineering Design Pattern in Software Engineering
Design Pattern in Software Engineering
Bilal Hassan
 
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
Simplilearn
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
CSS422 Week2 individual
CSS422 Week2 individualCSS422 Week2 individual
CSS422 Week2 individual
19eric76
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
sreeja_rajesh
 
Design patterns
Design patternsDesign patterns
Design patterns
Kolade Ibrahim Arowolo
 
common design patterns summary.pdf
common design patterns summary.pdfcommon design patterns summary.pdf
common design patterns summary.pdf
NikolayRaychev2
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
guestebd714
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
achraf_ing
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
Jay Kumarr
 
Design patterns
Design patternsDesign patterns
Design patterns
Akhilesh Joshi
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
C Meenakshi Meyyappan
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns Structural
UMAR ALI
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
jinaldesailive
 
Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through java
Aditya Bhuyan
 

Similar to designpatterns-.pdf (20)

Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Software design and Architecture.pptx
Software design and Architecture.pptxSoftware design and Architecture.pptx
Software design and Architecture.pptx
 
ap assignmnet presentation.pptx
ap assignmnet presentation.pptxap assignmnet presentation.pptx
ap assignmnet presentation.pptx
 
UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)UML Design Class Diagrams (2014)
UML Design Class Diagrams (2014)
 
Design Pattern in Software Engineering
Design Pattern in Software Engineering Design Pattern in Software Engineering
Design Pattern in Software Engineering
 
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
C# Design Patterns | Design Pattern Tutorial For Beginners | C# Programming T...
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
CSS422 Week2 individual
CSS422 Week2 individualCSS422 Week2 individual
CSS422 Week2 individual
 
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISESoftware Architecture and Project Management module III : PATTERN OF ENTERPRISE
Software Architecture and Project Management module III : PATTERN OF ENTERPRISE
 
Design patterns
Design patternsDesign patterns
Design patterns
 
common design patterns summary.pdf
common design patterns summary.pdfcommon design patterns summary.pdf
common design patterns summary.pdf
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
The 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summaryThe 23 gof design patterns in java ,the summary
The 23 gof design patterns in java ,the summary
 
Design pattern in android
Design pattern in androidDesign pattern in android
Design pattern in android
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Design patterns Structural
Design patterns StructuralDesign patterns Structural
Design patterns Structural
 
Basic design pattern interview questions
Basic design pattern interview questionsBasic design pattern interview questions
Basic design pattern interview questions
 
Design patterns through java
Design patterns through javaDesign patterns through java
Design patterns through java
 

Recently uploaded

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
Kamal Acharya
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
mahaffeycheryld
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
AnasAhmadNoor
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
snaprevwdev
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
PreethaV16
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
DharmaBanothu
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Massimo Talia
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
Shiny Christobel
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
OKORIE1
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 

Recently uploaded (20)

一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Supermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdfSupermarket Management System Project Report.pdf
Supermarket Management System Project Report.pdf
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Generative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdfGenerative AI Use cases applications solutions and implementation.pdf
Generative AI Use cases applications solutions and implementation.pdf
 
P5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civilP5 Working Drawings.pdf floor plan, civil
P5 Working Drawings.pdf floor plan, civil
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
openshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoinopenshift technical overview - Flow of openshift containerisatoin
openshift technical overview - Flow of openshift containerisatoin
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
OOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming languageOOPS_Lab_Manual - programs using C++ programming language
OOPS_Lab_Manual - programs using C++ programming language
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...This study Examines the Effectiveness of Talent Procurement through the Imple...
This study Examines the Effectiveness of Talent Procurement through the Imple...
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
 
Zener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and ApplicationsZener Diode and its V-I Characteristics and Applications
Zener Diode and its V-I Characteristics and Applications
 
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
DESIGN AND MANUFACTURE OF CEILING BOARD USING SAWDUST AND WASTE CARTON MATERI...
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 

designpatterns-.pdf

  • 1. Design patterns are known as best practices that the programmer can use to solve common problems when designing an application or system.
  • 2. Classification of Design Patterns Creational Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code. Structural Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. Behavioral Behavioral patterns take care of effective communication and the assignment of responsibilities between objects.
  • 3. Singleton Design Pattern Creational(1/4) Is a creational design pattern that lets you ensure that a class has only one instance, while providing a global access point to this instance. A Singleton encapsulates a unique resource and makes it readily available throughout the application
  • 4. Singleton Design Pattern Creational(1/4) When we use it ? - When a class in your program should have just a single instance available to all clients; for example, a single database object shared by different parts of the program. -Similarly, there can be a single configuration manager or error manager in an application that handles all problems instead of creating multiple managers. -Centralise logging staff
  • 5. Singleton Design Pattern Creational(1/4) Bad things? -Create a dependance for other classes who create the instance -Classes that depend on singletons are relatively harder to unit test in isolation.Directly impacting testability and maintainability -The Singleton design pattern promotes tight coupling between the classes in your application The pattern requires special treatment in a multithreaded environment so that multiple threads won’t create a singleton object several times.
  • 7. Factory Design Pattern Creational(2/4) Factory is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created. -Allows the consumer to create new objects without having to know the details of how they're created, or what their dependencies are -. they only have to give the information they actually want.
  • 8. Factory Design Pattern Creational(2/4) When we use it ? - You don’t know beforehand the exact types and dependencies of the objects your code should work with. -Construction is very complex and you need to reuse it. - You want to save system resources by reusing existing objects instead of rebuilding them each time.
  • 9. Factory Design Pattern Creational(2/4) When NOT use it ? - We don’t have any complex creation logic. if the factory doesn’t make any decision, the creation logic is very simple or is used only in a single place, the factory will be a needless abstraction.
  • 11. Builder Design Pattern Creational(3/4) Builder pattern builds a complex object using simple objects and using a step by step approach.The pattern allows you to produce different types and representations of an object using the same construction code. This builder is independent of other objects.
  • 12. Builder Design Pattern Creational(3/4) When we use it ? -When you want your code to be able to create different representations of some product. -When you want isolate complex construction code from the business logic of the product.
  • 13. Builder Design Pattern Creational(3/4) Example
  • 14. Prototype Design Pattern Creational(4/4) Prototype is a creational design pattern that lets you copy existing objects without making your code dependent on their classes.
  • 15. Prototype Design Pattern Creational(4/4) When we use it ? -when creation of object directly is costly (heavy process). For example, an object is to be created after a costly database operation. We can cache the object, returns its clone on next request and update the database as and when needed thus reducing database calls. Your code shouldn’t depend on the concrete classes of objects that you need to copy.
  • 17. Decorator Design Pattern Structural(1/3) Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors. The decorator pattern allows a user to add new functionality to an existing object without altering its structure.
  • 18. Decorator Design Pattern Structural(1/3) When we use it ? -When you need to be able to assign extra behaviors to objects at runtime without breaking the code that uses these objects. -When it’s difficult or not possible to extend an object’s behavior using inheritance.
  • 19. Decorator Design Pattern Structural(1/3) Example
  • 20. Proxy Design Pattern Structural(2/3) Proxy is a structural design pattern that lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate
  • 21. Proxy Design Pattern Structural(2/3) When we use it (1/2) ? you want only specific clients to be able to use the service object; for instance, when your objects are central parts of an operating system and clients are various launched applications (including malicious ones). The proxy can pass the request to the service object only if the client’s credentials match some criteria.(control proxy) Logging requests (logging proxy). This is when you want to keep a history of requests to the service object. The proxy can log each request before passing it to the service.
  • 22. Proxy Design Pattern Structural(2/3) When we use it (2/2) ? Caching request results (caching proxy). This is when you need to cache results of client requests and manage the life cycle of this cache, especially if results are quite large. The proxy can implement caching for recurring requests that always generate the same results
  • 23. Proxy Design Pattern Structural(2/3) Example
  • 24. Adapter Design Pattern Structural(3/3) Adapter is a structural design pattern that allows objects with incompatible interfaces to collaborate. This pattern involves a single class which is responsible to join functionalities of independent or incompatible interfaces. The Adapter pattern lets you create a middle-layer class that serves as a translator between your code and a legacy class, a 3rd-party class or any other class with a weird interface.
  • 25. Adapter Design Pattern Structural(3/3) When we use it ? -Use the Adapter class when you want to use some existing class, but its interface isn’t compatible with the rest of your code. -Use the pattern when you want to reuse several existing subclasses that lack some functionality that can’t be added to the superclass. -
  • 26. Adapter Design Pattern Structural(3/3) Example
  • 27. Iterator Design Pattern Behavioral(1/4) This pattern is used to get a way to access the elements of a collection object in a sequential manner without any need to know its underlying representation. (list, stack, tree, complex data structures.). As name implies, iterator helps in traversing the collection of objects in a defined manner which is useful the client applications.
  • 28. Iterator Design Pattern Behavioral(1/4) When we use it ? -when your collection has a complex data structure under the hood, but you want to hide its complexity from clients (either for convenience or security reasons). -when you want your code to be able to traverse different data structures or when types of these structures are unknown beforehand.
  • 30. Observer Design Pattern Behavioral(2/4) Observer is a behavioral design pattern that lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
  • 31. Observer Design Pattern Behavioral(2/4) When we use it ? -When some objects in your app must observe others, but only for a limited time or in specific cases. -When changes to the state of one object may require changing other objects, and the actual set of objects is unknown beforehand or changes dynamically.
  • 32. Observer Design Pattern Behavioral(2/4) Example
  • 33. Command Design Pattern Behavioral(3/4) Command is a behavioral design pattern that turns a request into a stand-alone object that contains all information about the request. This transformation lets you parameterize methods with different requests, delay or queue a request’s execution, and support undoable operations.
  • 34. Command Design Pattern Behavioral(3/4) -When you want to queue operations, schedule their execution, or execute them remotely. -when you want to implement reversible operations. (undo/redo, the Command pattern is perhaps the most popular of all.) -Use the Command pattern when you want to parametrize objects with operations. ( you can pass commands as method arguments, store them inside other objects, switch linked commands at runtime, etc.)
  • 35. Command Design Pattern Behavioral(3/4) Example
  • 36. Strategy Design Pattern Behavioral (4/4) Strategy is a behavioral design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.
  • 37. Strategy Design Pattern Behavioral (4/4) When we use it ? -you want to use different variants of an algorithm within an object and be able to switch from one algorithm to another during runtime. -you have a lot of similar classes that only differ in the way they execute some behavior.
  • 38. Strategy Design Pattern Behavioral (4/4) Example