Design Patterns (DP) - PowerPoint PPT Presentation

design patterns dp n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Design Patterns (DP) PowerPoint Presentation
Download Presentation
Design Patterns (DP)

play fullscreen
1 / 115
Design Patterns (DP)
381 Views
Download Presentation
colleen-beach
Download Presentation

Design Patterns (DP)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Gang of Four (GOF) Richard Helm Ralph Johnson John Vlissides Erich Gamma Design Patterns (DP) By P. S. Suryateja Asst. Professor CSE Dept Vishnu Institute of Technology

  2. Objectives • Know what are design patterns? • Know about GOF patterns. • How to select and use a pattern? • How to apply a pattern?

  3. Outline • Introduction to design patterns • What is a design pattern? • Need of design patterns • Use of design patterns • Design patterns in Smalltalk MVC • Describing design patterns • Catalog of design patterns • Organizing the catalog • How to select a design pattern? • How to use a design pattern?

  4. Outline (cont…) • Creational patterns • Introduction • Singleton • Abstract Factory • Factory Method • Builder • Prototype

  5. Outline (cont…) • Structural Patterns

  6. Introduction to Design Patterns

  7. What is a design pattern (DP)? “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice.” - Christopher Alexander Design patterns are repeatable / reusable solutions to commonly occurring problems in a certain context in software design.

  8. What is a design pattern (DP)? (cont…) Four essential elements of a pattern: • Pattern name • Problem • Solution • Consequences

  9. Need for design patterns • Designing reusable object-oriented software (API’s) is hard. • Experienced designers Vs novice designers. • Patterns make object-oriented software flexible, elegant and reusable. • Solved a problem previously but don’t remember when or how?

  10. Use of design patterns • Make it easier to reuse successful designs and architectures. • Make it easy for the new developers to design software. • Allows to choose different design alternatives to make the software reusable. • Helps in documenting and maintaining the software. To get a design “right”, faster.

  11. Why should we use DP’s? These are already tested and proven solutions used by many experienced designers.

  12. MVC Architecture

  13. Design Patterns in Smalltalk MVC

  14. Describing design patterns • Pattern name and classification • Intent • Also known as • Motivation • Applicability • Structure • Participants • Collaborations

  15. Describing design patterns (cont…) • Consequences • Implementation • Sample code • Known uses • Related patterns

  16. Catalog of design patterns • Abstract Factory • Adapter • Bridge • Builder • Chain of Responsibility • Command • Composite • Decorator • Façade • Factory Method

  17. Catalog of design patterns (cont…) • Flyweight • Interpreter • Iterator • Mediator • Memento • Observer • Prototype • Proxy • Singleton • State

  18. Catalog of design patterns (cont…) • Strategy • Template Method • Visitor

  19. Abstract Factory

  20. Adapter

  21. Bridge

  22. Builder

  23. Chain of Responsibility

  24. Command

  25. Composite

  26. Decorator

  27. Façade

  28. Factory Method

  29. Flyweight

  30. Interpreter

  31. Iterator

  32. Mediator

  33. Memento

  34. Observer

  35. Prototype

  36. Proxy

  37. Singleton

  38. State

  39. Strategy

  40. Template Method

  41. Visitor

  42. Organizing the catalog

  43. How to select a design pattern • Consider how design patterns solve design problems • Scan intent sections • Study how patterns interrelate • Study patterns of like purpose • Examine a cause of redesign • Consider what should be variable in your design

  44. Relationships between patterns

  45. How to use a design pattern • Read the pattern once through for a overview. • Study the structure, participants and collaborations sections. • Look at the sample code section to see a concrete example of the pattern in action. • Choose names for pattern participants that are meaningful in the application context. • Define the classes. • Define application-specific names for the operations in the pattern. • Implement the operations to carry out the responsibilities and collaborations in the pattern.

  46. Creational Patterns

  47. Introduction • Deals with how objects are created. • Increase the system’s flexibility in terms of what, who, how and when the object is created. • Further classified into two types: • Class-creational patterns • Object-creational patterns • Five creational patterns: • Abstract Factory • Builder • Factory Method • Prototype • Singleton

  48. Singleton Pattern • To create exactly one object of a class and to provide a global point of access to it. Structure

  49. Singleton Pattern (cont…) Non-Software Example

  50. Singleton Pattern (cont…) Motivation: • Need to create exactly one user interface object. • Need to create only one print spooler.