html5-img
1 / 21

Lecture 12 Introduction to Design Patterns

SWE 316: Software Design and Architecture. Lecture 12 Introduction to Design Patterns. Ch 6. Explain the purpose and the general form of design patterns. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission. 2/21. Motivation.

milek
Download Presentation

Lecture 12 Introduction to Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SWE 316: Software Design and Architecture Lecture 12Introduction to Design Patterns Ch 6 • Explain the purpose and the general form of design patterns. Adapted from Software Design: From Programming to Architecture by Eric J. Braude (Wiley 2003), with permission.

  2. 2/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Design Purposes • Reusability, Flexibility, and Maintainability • Reuse flexible designs • Keep code at a general level • Minimize dependency on other classes • Robustness • Reuse reliable designs • Reuse robust parts • Sufficiency / Correctness • Modularize design • Reuse trusted parts 6.1

  3. 3/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Motivation • OOD methods emphasize design notations • Fine for specification, documentation • But OOD is more than just drawing diagrams • Good OO designers rely on lots of experience • Most powerful reuse is design reuse • Match problem to design experience Based on material produced by Prof. Douglas C. Schmidt

  4. 4/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Why do we need Design Patterns? • There is a “designer” and there is a “good designer” • Knowing concepts like abstraction, inheritance, polymorphism, etc. does not “necessary” make you a good designer • A good designer knows how to combine these concepts to make flexible, maintainable, and reusable designs. • Using design patterns: • Some body already solved a similar problem • Problem:capturing, communicating, & applying this knowledge 1 2 3

  5. 5/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Reasons for studying design patterns • Reuse existing, high-quality solutions to commonly recurring problems. • Establish common terminology to improve communications within teams. • Shift the level of thinking to a higher perspective. • Decide whether you have the right design, not just one that works. • Improve individual learning and team learning. • Improve the modifiability of code. • Facilitate adoption of improved design alternatives, even when patterns are not used explicitly. • Discover alternatives to large inheritance hierarchies.

  6. 6/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Students activity (how to do this?) Design Goal: Flexibility

  7. 7/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion What are design patterns? • Design patterns are class combinations and accompanying algorithms that fulfill common design purposes • Design pattern expresses an idea • Another Definition “Design patterns are descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context. 6.2

  8. 8/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Design Patterns by Type 1- Creational patterns: used to create objects in flexible or constrained ways. 2 - Structural patterns: used to represent data structures such as trees, with uniform processing interfaces. 3 - Behavioral patterns: capturing behavior among a collection of objects. 6.3

  9. 9/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Types of design patterns (cont.)

  10. 10/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Creational design patterns • These patterns provide guidance on the creation of objects. • They help hide the details of the object instantiation from the code that uses those objects. • They make a system independent of how its objects are created, composed and represented. • This leads to low coupling between the users and the way the objects are created. • Patterns Factory Abstract Factory Singleton Builder Prototype

  11. 11/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Structural design patterns • These patterns describe the organization of objects; that is, how classes and objects are composed to form larger structures. • Patterns -Adapter -Bridge -Composite -Decorator -Facade -Flyweight -Proxy

  12. 12/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Behavioral design patterns • These patterns are concerned with organizing, managing and assigning responsibilities to objects during execution. • The focus is on communication between the objects involved during some task. • Typically, these patterns characterize complex control flows that are difficult to follow at run time. • They therefore help to shift the emphasis away from the low-level flow of control to the higher level object interactions. -Chain of Responsibility -Command -Interpreter -Iterator -Mediator -Memento-Observer -State -Strategy-Template -Visitor

  13. 13/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Characteristics of Design Patterns 1 • Viewpoints – ways to describe patterns • Static: class model (building blocks) • Dynamic: sequence or state diagram (operation) • Levels – decomposition of patterns • Abstract level describes the core of the pattern • Concrete (= non abstract) level describes the particulars of this case • Roles –the “players” in pattern usage • Application of the design pattern itself • Clients of the design pattern application • Setup code initializes and controls

  14. 14/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Characteristics of Design Patterns 2 (class or classes) 1. Client role 3. Role: Application of the design pattern A. Static viewpoint B. Dynamic viewpoint A B (i) Abstract level (ii) Concrete level C D (sequence or state diagram) (class model) 2. Setup role : Reference direction (class or classes)

  15. 15/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Viewpoints & Levels • Two viewpoints • We consider design patterns from the static viewpoint (what they are made from) and the dynamic viewpoint (how they function). • Levels • Design patterns usually have an abstract level and a non-abstract (“concrete”) level.

  16. 16/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Design Patterns Forms • Delegation • Recursion 6.5

  17. 17/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Basic Idea of Delegation … clientFunction( … ) { … intermediaryFunction( … ) … } … intermediaryFunction( … ) { … requiredFunction() … } Client clientFunction() intermediaryFunction()  replace requiredFunction()

  18. 18/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Basic Design Pattern Form #1: Delegation Client … interfaceMethod( … ) { … doerObject.doIt() … } doerObject DPInterface interfaceMethod() DoerBase doIt() ConcreteDoer1 doIt() ConcreteDoer2 doIt() . . .

  19. 19/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Basic Design Pattern Form #2: Recursion RecursionBase doOperation() Client aggregate NonrecursiveClass doOperation() RecursiveClass doOperation() void doOperation( … ) { … aggregate … }

  20. 20/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion The Recursion Form Applied to an Organization Chart Employee printOrganization() Client supervisees IndividualContributor printOrganization() Supervisor printOrganization() void printOrganization( … ) { … supervisees.printOrganization() … }

  21. 21/21 Motivation Design Patterns Characteristics of DP's DP's Forms: Delegation and Recursion Summary of This Chapter • Design Patterns are recurring designs satisfying recurring design purposes • Classified as Creational, Structural, or Behavioral • Described by Static and Dynamic Viewpoints • Typically class models and sequence diagrams respectively • Design patterns Forms usually Delegation or Recursion

More Related