SlideShare a Scribd company logo
1 of 34
OOP Design
Patterns
OOP Design Patterns
• Contents
• Patterns classification
• Observer
• Singleton
• Builder
• Chain of responsibility
• Proxy
• Decorator
• Template method
• Service Locator
• Conclusion
Patterns classification
• Creational
• In software engineering, creational design patterns are design
patterns that deal with object creation mechanisms, trying to create
objects in a manner suitable to the situation.
• Structural
• In software engineering, structural design patterns are design
patterns that ease the design by identifying a simple way to realize
relationships between entities.
• Behavioral
• In software engineering, behavioral design patterns are design
patterns that identify common communication patterns between
objects and realize these patterns. By doing so, these patterns
increase flexibility in carrying out this communication.
Observer
• Usage
• In this pattern, there are many observers (objects) which are
observing a particular subject (object).
• Computer example
• java.util.Observable
(rarely used in real world though)
• javax.servlet.http
.HttpSessionBindingListener
Observer diagram
Singleton
• Usage
• A particular class should have only one instance. We will use only
that instance whenever we are in need.
• Computer example
• In a software system sometimes we may decide to use only one
file system. Usually we may use it for the centralized management
of resources. Connection Manager.
java.lang.Runtime#getRuntime()
java.awt.Desktop#getDesktop()
java.lang.System#getSecurityManager()
UML diagram
Singleton code example
Decorator
• Concept
• Attach additional responsibilities to an object dynamically. Decorators
provide a flexible alternative to subclassing for extending functionality
• Using
• The pattern is useful when a creational algorithm of a complex object
is independent of the assembly of the parts of the object. The
construction process is also capable of building a different
representation of that object under consideration.
• All subclasses of java.io.inputStream, Reader …
• Javax.servlet.HttoServeltRequestWrapper
UML diagram
Proxy
• Concept
• We want to use a class which can perform as an interface to
something else.
• General type of proxy
• Remote proxies. They will hide that actual object which is in a
different address space.
• Protection proxy. It limits permission to
functional.
• Virtual proxy create lazy loading of object
• Smart reference proxy add additional
functional
UML Diagram
Chain of responsibility
Chain of responsibility
• Concept
• Avoid coupling the sender of a request to its receiver by giving
more than one object a chance to handle the request. Chain the
receiving objects and pass the request along the chain until an
object handles it.
• Using
• Chain of responsibility pattern is used to achieve loose coupling in
software design where a request from client is passed to a chain of
objects to process them.
UML Diagram
Builder
• Concept
• Builder use for dealing with constructors that require too many
parameters.
• Using
Prototype
• Concept
• Specify the kinds of objects to create using a prototypical instance,
and create new objects by copying this prototype.
• Using
• Java.lang.Object#clone()
• Concept
• Define the skeleton of an algorithm in an operation, deferring some
steps to subclasses. The template method lets subclasses redefine
certain steps of an algorithm without changing the algorithm’s
structure.
• Using
• java.util.Comparator#compare(), executed by among others
Collections#sort().
• javax.servlet.http.HttpServlet, the service() and all doXXX() methods
take HttpServletRequest and HttpServletResponse and the
implementor has to process them (and not to get hold of them as
instance variables!).
• javax.servlet.Filter#doFilter()
UML diagram
Factory method
• Concept
• Define an interface for creating an object, but let subclasses decide
which class to instantiate. The factory method lets a class defer
instantiation to subclasses.
• Using
• java.util.Calendar#getInstance()
• java.util.ResourceBundle#getBundle()
• java.text.NumberFormat#getInstance()
• java.nio.charset.Charset#forName()
• java.net.URLStreamHandlerFactory#createURLStreamHandler(String)
(Returns singleton object per protocol)
UML diagram
Service Locator
• Is it antipattern?
• Context
• Service lookup and creation involves complex interfaces and network
operations.
• Using
• EJB clients need to use the JNDI API to look up EJBHome objects by
using the enterprise bean's registered JNDI name.
• JMS clients need to use JNDI API to look up JMS components by
using the JNDI names registered for JMS components, such as
connection factories, queues, and topics.
UML Diagram
Conclusions
• OOP Patterns can make your life and code better.
• All of them need a lot of practice.
• Be careful with using patterns.
• Avoid antipatterns;
Thank you for attention
The end
USA HQ
Toll Free: 866-687-3588
Tel: +1-512-516-8880
Ukraine HQ
Tel: +380-32-240-9090
Bulgaria
Tel: +359-2-902-3760
Germany
Tel: +49-69-2602-5857
Netherlands
Tel: +31-20-262-33-23
Poland
Tel: +48-71-382-2800
UK
Tel: +44-207-544-8414
EMAIL
info@softserveinc.com
WEBSITE:
www.softserveinc.com
THE END

More Related Content

What's hot

Mac/iOS Design Patterns
Mac/iOS Design PatternsMac/iOS Design Patterns
Mac/iOS Design PatternsRobert Brown
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design PatternJaswant Singh
 
iOS viper presentation
iOS viper presentationiOS viper presentation
iOS viper presentationRajat Datta
 
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan VujaklijaInfinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan VujaklijaInfinum
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - IntroductionSagar Acharya
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design PatternsLilia Sfaxi
 
Object Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) javaObject Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) javaGaddafiAdamu1
 
Prototype Pattern
Prototype PatternPrototype Pattern
Prototype PatternIder Zheng
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCAndy Butland
 
Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0Laurent Cerveau
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
 
You Used To Inject Me In Your Constructor
 You Used To Inject Me In Your Constructor You Used To Inject Me In Your Constructor
You Used To Inject Me In Your ConstructorVeronica Lillie
 
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum
 

What's hot (20)

Mac/iOS Design Patterns
Mac/iOS Design PatternsMac/iOS Design Patterns
Mac/iOS Design Patterns
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
iOS viper presentation
iOS viper presentationiOS viper presentation
iOS viper presentation
 
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan VujaklijaInfinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
Infinum iOS Talks #2 - VIPER for everybody by Damjan Vujaklija
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Object Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) javaObject Oriented Prograring(OOP) java
Object Oriented Prograring(OOP) java
 
Extjs
ExtjsExtjs
Extjs
 
Prototype Pattern
Prototype PatternPrototype Pattern
Prototype Pattern
 
Driver
DriverDriver
Driver
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0Paris Tech Meetup talk : Troubles start at version 1.0
Paris Tech Meetup talk : Troubles start at version 1.0
 
Core Data
Core DataCore Data
Core Data
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
You Used To Inject Me In Your Constructor
 You Used To Inject Me In Your Constructor You Used To Inject Me In Your Constructor
You Used To Inject Me In Your Constructor
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactive
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
 
Grails with swagger
Grails with swaggerGrails with swagger
Grails with swagger
 

Viewers also liked (18)

NoProblem Radiation vs Health
NoProblem Radiation vs HealthNoProblem Radiation vs Health
NoProblem Radiation vs Health
 
Rafael rivero
Rafael riveroRafael rivero
Rafael rivero
 
Los planetas. roxana infantes
Los planetas. roxana infantesLos planetas. roxana infantes
Los planetas. roxana infantes
 
Inflación Noviembre 2015
Inflación Noviembre 2015Inflación Noviembre 2015
Inflación Noviembre 2015
 
Windows registry forensics
Windows registry forensicsWindows registry forensics
Windows registry forensics
 
Kamil final
Kamil finalKamil final
Kamil final
 
7027
70277027
7027
 
Exportaciones-Sep 2015
Exportaciones-Sep 2015Exportaciones-Sep 2015
Exportaciones-Sep 2015
 
Social Media Diary & Analysis. ChelseaWilliams
Social Media Diary & Analysis. ChelseaWilliamsSocial Media Diary & Analysis. ChelseaWilliams
Social Media Diary & Analysis. ChelseaWilliams
 
sesion nro 05_06-02-2016_internet
sesion nro 05_06-02-2016_internetsesion nro 05_06-02-2016_internet
sesion nro 05_06-02-2016_internet
 
Actividad 2 unidad 3
Actividad 2  unidad 3Actividad 2  unidad 3
Actividad 2 unidad 3
 
Forget Me Not
Forget Me NotForget Me Not
Forget Me Not
 
Forget Me Not
Forget Me NotForget Me Not
Forget Me Not
 
. New article.BPI
. New article.BPI. New article.BPI
. New article.BPI
 
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End allgroup 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
group 01 - Arndt_Alex_alexma2_CEEn 544 Case Study (Crookston) End all
 
NUS Teaching Assistant Feedback: CS1010E (Andre Lim)
NUS Teaching Assistant Feedback: CS1010E (Andre Lim)NUS Teaching Assistant Feedback: CS1010E (Andre Lim)
NUS Teaching Assistant Feedback: CS1010E (Andre Lim)
 
Cuadro resumen filososofia
Cuadro resumen filososofiaCuadro resumen filososofia
Cuadro resumen filososofia
 
Instalación de SQL Server 2014
Instalación de SQL Server 2014Instalación de SQL Server 2014
Instalación de SQL Server 2014
 

Similar to PresentationPatterns_v2

Design patterns
Design patternsDesign patterns
Design patternsAlok Guha
 
MVC + ORM (with project implementation)
MVC + ORM (with project implementation)MVC + ORM (with project implementation)
MVC + ORM (with project implementation)Prateek Chauhan
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptSanthosh Kumar Srinivasan
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptxSachin Patidar
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Reviewnetc2012
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayLuka Zakrajšek
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSergey Aganezov
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor FrameworkDamien Magoni
 
Software variability management - 2017
Software variability management - 2017Software variability management - 2017
Software variability management - 2017XavierDevroey
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts weili_at_slideshare
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overviewumesh patil
 
P Training Presentation
P Training PresentationP Training Presentation
P Training PresentationGaurav Tyagi
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Salesforce Developers
 

Similar to PresentationPatterns_v2 (20)

Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
AngularJS
AngularJSAngularJS
AngularJS
 
Design patterns
Design patternsDesign patterns
Design patterns
 
MVC + ORM (with project implementation)
MVC + ORM (with project implementation)MVC + ORM (with project implementation)
MVC + ORM (with project implementation)
 
Introduction to Design Patterns in Javascript
Introduction to Design Patterns in JavascriptIntroduction to Design Patterns in Javascript
Introduction to Design Patterns in Javascript
 
Creational Design Patterns.pptx
Creational Design Patterns.pptxCreational Design Patterns.pptx
Creational Design Patterns.pptx
 
Design p atterns
Design p atternsDesign p atterns
Design p atterns
 
Frameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic ReviewFrameworks Galore: A Pragmatic Review
Frameworks Galore: A Pragmatic Review
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Akka.Net Overview
Akka.Net OverviewAkka.Net Overview
Akka.Net Overview
 
Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
Software Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural PatternsSoftware Design Patterns. Part I :: Structural Patterns
Software Design Patterns. Part I :: Structural Patterns
 
The Meteor Framework
The Meteor FrameworkThe Meteor Framework
The Meteor Framework
 
Software variability management - 2017
Software variability management - 2017Software variability management - 2017
Software variability management - 2017
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Design_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.pptDesign_Patterns_Dr.CM.ppt
Design_Patterns_Dr.CM.ppt
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overview
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1Mastering the Lightning Framework - Part 1
Mastering the Lightning Framework - Part 1
 

PresentationPatterns_v2

  • 2. OOP Design Patterns • Contents • Patterns classification • Observer • Singleton • Builder • Chain of responsibility • Proxy • Decorator • Template method • Service Locator • Conclusion
  • 3. Patterns classification • Creational • In software engineering, creational design patterns are design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. • Structural • In software engineering, structural design patterns are design patterns that ease the design by identifying a simple way to realize relationships between entities. • Behavioral • In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
  • 4. Observer • Usage • In this pattern, there are many observers (objects) which are observing a particular subject (object). • Computer example • java.util.Observable (rarely used in real world though) • javax.servlet.http .HttpSessionBindingListener
  • 6.
  • 7. Singleton • Usage • A particular class should have only one instance. We will use only that instance whenever we are in need. • Computer example • In a software system sometimes we may decide to use only one file system. Usually we may use it for the centralized management of resources. Connection Manager. java.lang.Runtime#getRuntime() java.awt.Desktop#getDesktop() java.lang.System#getSecurityManager()
  • 10.
  • 11. Decorator • Concept • Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality • Using • The pattern is useful when a creational algorithm of a complex object is independent of the assembly of the parts of the object. The construction process is also capable of building a different representation of that object under consideration. • All subclasses of java.io.inputStream, Reader … • Javax.servlet.HttoServeltRequestWrapper
  • 13.
  • 14. Proxy • Concept • We want to use a class which can perform as an interface to something else. • General type of proxy • Remote proxies. They will hide that actual object which is in a different address space. • Protection proxy. It limits permission to functional. • Virtual proxy create lazy loading of object • Smart reference proxy add additional functional
  • 16.
  • 18. Chain of responsibility • Concept • Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. • Using • Chain of responsibility pattern is used to achieve loose coupling in software design where a request from client is passed to a chain of objects to process them.
  • 20.
  • 21. Builder • Concept • Builder use for dealing with constructors that require too many parameters. • Using
  • 22.
  • 23. Prototype • Concept • Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. • Using • Java.lang.Object#clone()
  • 24. • Concept • Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. The template method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure. • Using • java.util.Comparator#compare(), executed by among others Collections#sort(). • javax.servlet.http.HttpServlet, the service() and all doXXX() methods take HttpServletRequest and HttpServletResponse and the implementor has to process them (and not to get hold of them as instance variables!). • javax.servlet.Filter#doFilter()
  • 26.
  • 27. Factory method • Concept • Define an interface for creating an object, but let subclasses decide which class to instantiate. The factory method lets a class defer instantiation to subclasses. • Using • java.util.Calendar#getInstance() • java.util.ResourceBundle#getBundle() • java.text.NumberFormat#getInstance() • java.nio.charset.Charset#forName() • java.net.URLStreamHandlerFactory#createURLStreamHandler(String) (Returns singleton object per protocol)
  • 29. Service Locator • Is it antipattern? • Context • Service lookup and creation involves complex interfaces and network operations. • Using • EJB clients need to use the JNDI API to look up EJBHome objects by using the enterprise bean's registered JNDI name. • JMS clients need to use JNDI API to look up JMS components by using the JNDI names registered for JMS components, such as connection factories, queues, and topics.
  • 31. Conclusions • OOP Patterns can make your life and code better. • All of them need a lot of practice. • Be careful with using patterns. • Avoid antipatterns;
  • 32. Thank you for attention
  • 34. USA HQ Toll Free: 866-687-3588 Tel: +1-512-516-8880 Ukraine HQ Tel: +380-32-240-9090 Bulgaria Tel: +359-2-902-3760 Germany Tel: +49-69-2602-5857 Netherlands Tel: +31-20-262-33-23 Poland Tel: +48-71-382-2800 UK Tel: +44-207-544-8414 EMAIL info@softserveinc.com WEBSITE: www.softserveinc.com THE END