SlideShare a Scribd company logo
1 of 27
Design Patterns

                                   Chapter 8




Object-Oriented Software Systems Engineering – Chapter 8   Slide 1
Objectives

 In this chapter we will:
  Discuss why software design patterns evolved
  Define and describe a software design pattern
  Describe fundamental patterns (GRASP patterns)




Object-Oriented Software Systems Engineering – Chapter 8   Slide 2
Design Patterns – An Introduction

  Objectives
     Understand why software design patterns evolved
     Define and describe a software design pattern
     Describe fundamental patterns (GRASP patterns)




Object-Oriented Software Systems Engineering – Chapter 8   Slide 3
Why patterns?

  designing reusable software is hard
  novices are overwhelmed
  experts draw from experience
  some design solutions reoccur
  understanding reoccurring solutions is beneficial
    in several ways




Object-Oriented Software Systems Engineering – Chapter 8   Slide 4
Why patterns?


                “Wisdom is often ascribed to those
                    who can tell just the right story
                  at the right moment and who often
                have a large number of stories to tell.”


                                Robert C. Shank




Object-Oriented Software Systems Engineering – Chapter 8   Slide 5
What is a pattern?
Occurrence


  chess                                 from rules to expertise
  literature                            oldest reference
  agriculture                           wisdom vs. science
  fishing                               anecdotal documentation
  architecture                          pioneer work
  software design




Object-Oriented Software Systems Engineering – Chapter 8      Slide 6
Architectural Patterns


Light from two sides
                                                           Place at
                                                           Window




                           Deep terrace




Object-Oriented Software Systems Engineering – Chapter 8              Slide 7
What is a pattern?


    “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.”

                                                           Alexander et al.




Object-Oriented Software Systems Engineering – Chapter 8             Slide 8
What is a pattern?
Patterns are proven




   “Aggressive disregard for originality”
   Rule of three

           “Once is an event, twice is an incident,
            thrice it's a pattern.”
                              Jerry Weinberg




Object-Oriented Software Systems Engineering – Chapter 8   Slide 9
The Origins of Design Patterns

  They originate from the work of Christopher
   Alexander, a building architect in the 1970’s.
  Alexander’s idea was to improve the quality of the
   buildings of the time by utilising proven ‘patterns’
   of good architectural design.
  ‘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.’




Object-Oriented Software Systems Engineering – Chapter 8   Slide 10
From Buildings to Software

  Alexander’s work ‘discovered’ by Kent Beck and
    friends in the 1980’s.




  They applied Alexander’s ideas about constructing
   buildings to the building of software.
  Patterns are found in all areas of computing, from
   user interface design, the writing of device drivers
   to the use of databases.



Object-Oriented Software Systems Engineering – Chapter 8   Slide 11
What is a software pattern?

  proven software practice
  piece of literature
  building block
  possible abstraction levels:
     language construct
     idiom
     design pattern
     architectural pattern




Object-Oriented Software Systems Engineering – Chapter 8   Slide 12
What is a Design Pattern?

  A design pattern is defined as ‘ a description of
   communicating objects and classes that are
   customised to solve a general design problem in a
   particular context’.
  Patterns capture good design principles and
   communicate them to others.
  Design patterns represent the first legitimate
   attempt at design reusability.




Object-Oriented Software Systems Engineering – Chapter 8   Slide 13
What is a software pattern?


     “A methodology tells you how to write down the
                  decisions you have made.
     A pattern tells you which decisions to make, when
                    and how to make them,
                 and why they are the right”

                                                           Beck & Johnson




Object-Oriented Software Systems Engineering – Chapter 8            Slide 14
GRASP Patterns

  General Responsibility Assigning Software
    Patterns
       Five patterns
              Expert
              Creator
              High Cohesion
              Low coupling
              Controller




Object-Oriented Software Systems Engineering – Chapter 8   Slide 15
Expert
  Expert
     Assign responsibility to the information expert

              Sale
         date
         time                                                 Product
                 Contains                                   Specification
                1..*                                        description
                               Described-by                 price
           Sales       *
                                                            UPC
         LineItem
        quantity


      • What about responsibilities for
         • grandTotal of sale
                 • You also need subtotal for a line item
                 • A method to return the price

Object-Oriented Software Systems Engineering – Chapter 8                    Slide 16
Expert
          Sale
       date
       time
       total sales()

              Contains

               1..*                                          Product
                               Described-by                Specification
          Sales        *
        LineItem                                           description
                                                           price
        quantity
                                                           UPC
        subtotal()
                                                           getPrice()


  Benefits
       Encapsulation is maintained. Supports low coupling
        which leads to robust and maintainable systems


Object-Oriented Software Systems Engineering – Chapter 8                   Slide 17
Creator
    Creator - Assign class B the responsibility to create an
     instance of class A if one of the following is true
              B aggregates or contains A objects
              B records instances of A objects
              B closely uses A objects
              B has the intializing data that will be passed to A when created

    Who should be responsible for creating a
      SalesLineItem instance?
                        Sale
                   date
                   time                                          Product
                          Contains                             Specification
                         1..*                                  description
                     Sales                Described-by         price
                               *
                   LineItem                                    UPC

                   quantity

Object-Oriented Software Systems Engineering – Chapter 8             Slide 18
Low Coupling

Design 1
  makePayment()                         1:create()
                        :POST                                  p:Payment


                                2:addPayment(p)
                                                                  :Sale

Design 2

   makePayment()                     1:makePayment(p)
                         :POST                                     :Sale

                                                           1.1create()

                                                                 p:Payment

Object-Oriented Software Systems Engineering – Chapter 8                     Slide 19
High Coupling
    Design 1

         Sale                                               Payment
   date              1      Paid-by               1
   Time                                                    amount
   payment                                                 getAmount()
                      1
   totalSales()
   addPayment(p)        Captures
   makeLineItem(i,q)          1
                                          Post                  sale.makeLineItem(item,qty)
                                    sale
                                    endSale()
     Payment p = new                enterItem(item,qty)
     Payment(cash);                 makePayment(cash)
     sale.addPayment(p);




Object-Oriented Software Systems Engineering – Chapter 8                       Slide 20
Low Coupling
      Design 2

           Sale                                             Payment
      date            1     Paid-by               1
      Time                                                 amount
      payment                                              getAmount()
                       1
      totalSales()
      makeLineItem(i,q) Captures
      makePayment(cash)       1    Post                        sale.makeLineItem(item,qty)

                                    sale
                                    endSale()
        Payment p = new             enterItem(item,qty)
        Payment(cash)               makePayment(cash)



                                                      sale.makePayment(cash)



Object-Oriented Software Systems Engineering – Chapter 8                        Slide 21
High Cohesion

  Same example can be analysed from point of view
   of high cohesion (functional cohesion)
  Design two is better




Object-Oriented Software Systems Engineering – Chapter 8   Slide 22
Controller

  Assign responsibility for handling a system event
    messages
       Usually assigned to a controller
       Logically the controller should not be a “window”,
        “Frame”, “applet”, “application” e.t.c. these classes just
        handle the events and delegate them to a controller.
       In practice view and control may be embedded in a single
        element known as a UI delegate (MVC architecture)
       endSale(), enterItem() & makePayment() are embedded
        into the POST class




Object-Oriented Software Systems Engineering – Chapter 8     Slide 23
Design Patterns: Essentials

  Patterns are found through trial and error and by
   observation.
  In general a design pattern has four essential
   elements:
       The   pattern name
       The   problem the pattern is used to solve
       The   solution or template for implementing the pattern
       The   consequences or results of applying the pattern.




Object-Oriented Software Systems Engineering – Chapter 8      Slide 24
Patterns in the S/W Development Lifecycle

  Design patterns are considered complementary to
   existing object-oriented methodologies.
  Success in using design patterns largely depends
   in the correct selection of the appropriate pattern.
  Knowledge and understanding of the use of
   existing documented patterns is all important.
  Therefore the way patterns are catalogued must
   be unambiguous and complete.




Object-Oriented Software Systems Engineering – Chapter 8   Slide 25
The ‘Gang of Four’

  The most widely known work on design patterns is
   that of Gamma, Helm, Johnson and Vlissides .
   ‘The gang of four’ as they are commonly referred
   to.
  Their book ‘Design Patterns: Elements of
   Reusable Object-Oriented Software’ was
   published in 1994.
  It contains a description of the concepts of
   patterns, plus a catalog of 23 design patterns with
   their full documentation.




Object-Oriented Software Systems Engineering – Chapter 8   Slide 26
Summary

 In this chapter we have:
  Discussed why software design patterns evolved
  Defined and described a software design pattern
  Described fundamental patterns (GRASP patterns)




Object-Oriented Software Systems Engineering – Chapter 8   Slide 27

More Related Content

What's hot

12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17Niit Care
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingJoel Falcou
 
ASPECT ORIENTED PROGRAMING(aop)
ASPECT ORIENTED PROGRAMING(aop)ASPECT ORIENTED PROGRAMING(aop)
ASPECT ORIENTED PROGRAMING(aop)kvsrteja
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19Niit Care
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08Niit Care
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Marco Brambilla
 
Good code-isnt-enough
Good code-isnt-enoughGood code-isnt-enough
Good code-isnt-enoughSkills Matter
 
Open gl programming guide
Open gl programming guideOpen gl programming guide
Open gl programming guideRohit Bapat
 
Secure Communication with Privacy Preservation in VANET
Secure Communication with Privacy Preservation in VANETSecure Communication with Privacy Preservation in VANET
Secure Communication with Privacy Preservation in VANETAnkit Gupta
 
Survey paper
Survey paperSurvey paper
Survey paperIJASCSE
 
Pr 005 qa_workshop
Pr 005 qa_workshopPr 005 qa_workshop
Pr 005 qa_workshopFrank Gielen
 

What's hot (14)

12 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_1712 iec t1_s1_oo_ps_session_17
12 iec t1_s1_oo_ps_session_17
 
01 gui 01
01 gui 0101 gui 01
01 gui 01
 
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel ComputingGenerative and Meta-Programming - Modern C++ Design for Parallel Computing
Generative and Meta-Programming - Modern C++ Design for Parallel Computing
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 
ASPECT ORIENTED PROGRAMING(aop)
ASPECT ORIENTED PROGRAMING(aop)ASPECT ORIENTED PROGRAMING(aop)
ASPECT ORIENTED PROGRAMING(aop)
 
Sa 008 patterns
Sa 008 patternsSa 008 patterns
Sa 008 patterns
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
 
06 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_0806 iec t1_s1_oo_ps_session_08
06 iec t1_s1_oo_ps_session_08
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...
 
Good code-isnt-enough
Good code-isnt-enoughGood code-isnt-enough
Good code-isnt-enough
 
Open gl programming guide
Open gl programming guideOpen gl programming guide
Open gl programming guide
 
Secure Communication with Privacy Preservation in VANET
Secure Communication with Privacy Preservation in VANETSecure Communication with Privacy Preservation in VANET
Secure Communication with Privacy Preservation in VANET
 
Survey paper
Survey paperSurvey paper
Survey paper
 
Pr 005 qa_workshop
Pr 005 qa_workshopPr 005 qa_workshop
Pr 005 qa_workshop
 

Viewers also liked

5. state diagrams
5. state diagrams5. state diagrams
5. state diagramsAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using umlAPU
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_moduleAPU
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagramsAPU
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagramweichen
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagramsAPU
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagramRahul Pola
 
Collaboration Diagram
Collaboration DiagramCollaboration Diagram
Collaboration Diagramfahad_uaar
 
Chapter 5 software design
Chapter 5 software designChapter 5 software design
Chapter 5 software designPiyush Gogia
 
Erp --functional-modules
Erp --functional-modulesErp --functional-modules
Erp --functional-modulesRavi shankar
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principlessaurabhshertukde
 

Viewers also liked (13)

5. state diagrams
5. state diagrams5. state diagrams
5. state diagrams
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
4. class diagrams using uml
4. class diagrams using uml4. class diagrams using uml
4. class diagrams using uml
 
01 introduction to_module
01 introduction to_module01 introduction to_module
01 introduction to_module
 
6. activity diagrams
6. activity diagrams6. activity diagrams
6. activity diagrams
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
7. sequence and collaboration diagrams
7. sequence and collaboration diagrams7. sequence and collaboration diagrams
7. sequence and collaboration diagrams
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
 
Flow charts
Flow chartsFlow charts
Flow charts
 
Collaboration Diagram
Collaboration DiagramCollaboration Diagram
Collaboration Diagram
 
Chapter 5 software design
Chapter 5 software designChapter 5 software design
Chapter 5 software design
 
Erp --functional-modules
Erp --functional-modulesErp --functional-modules
Erp --functional-modules
 
Design concepts and principles
Design concepts and principlesDesign concepts and principles
Design concepts and principles
 

Similar to Design Patterns Chapter Overview

Cs 1023 lec 4 (week 1)
Cs 1023 lec 4 (week 1)Cs 1023 lec 4 (week 1)
Cs 1023 lec 4 (week 1)stanbridge
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design patternchetankane
 
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...Till Riedel
 
Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User InterfacePedro J. Molina
 
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDSFACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDSIRJET Journal
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture PortfolioMajong DevJfu
 
Rhapsody reverseengineering
Rhapsody reverseengineeringRhapsody reverseengineering
Rhapsody reverseengineeringScott Althouse
 
Devnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology
 
Lecture 7 agile software development (2)
Lecture 7   agile software development (2)Lecture 7   agile software development (2)
Lecture 7 agile software development (2)IIUI
 
9.oo languages
9.oo languages9.oo languages
9.oo languagesAPU
 
Developer Friendly API Design
Developer Friendly API DesignDeveloper Friendly API Design
Developer Friendly API Designtheamiableapi
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstEnea Gabriel
 
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...Prolifics
 
Framework Engineering_Final
Framework Engineering_FinalFramework Engineering_Final
Framework Engineering_FinalYoungSu Son
 
Architecture As Language
Architecture As LanguageArchitecture As Language
Architecture As Languageguest2e0b3a
 

Similar to Design Patterns Chapter Overview (20)

Cs 1023 lec 4 (week 1)
Cs 1023 lec 4 (week 1)Cs 1023 lec 4 (week 1)
Cs 1023 lec 4 (week 1)
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
 
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...
Thesis presentation: Middleware for Ubicomp - A Model Driven Development Appr...
 
Modelling the User Interface
Modelling the User InterfaceModelling the User Interface
Modelling the User Interface
 
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDSFACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
FACE COUNTING USING OPEN CV & PYTHON FOR ANALYZING UNUSUAL EVENTS IN CROWDS
 
Build 2019 Recap
Build 2019 RecapBuild 2019 Recap
Build 2019 Recap
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio
 
Rhapsody reverseengineering
Rhapsody reverseengineeringRhapsody reverseengineering
Rhapsody reverseengineering
 
Devnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology back toschool software reengineering
Devnology back toschool software reengineering
 
Sa 009 add
Sa 009 addSa 009 add
Sa 009 add
 
Sa002 abc
Sa002 abcSa002 abc
Sa002 abc
 
Lecture 7 agile software development (2)
Lecture 7   agile software development (2)Lecture 7   agile software development (2)
Lecture 7 agile software development (2)
 
9.oo languages
9.oo languages9.oo languages
9.oo languages
 
Developer Friendly API Design
Developer Friendly API DesignDeveloper Friendly API Design
Developer Friendly API Design
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
 
Framework Engineering_Final
Framework Engineering_FinalFramework Engineering_Final
Framework Engineering_Final
 
Fdd presentation
Fdd presentationFdd presentation
Fdd presentation
 
Architecture As Language
Architecture As LanguageArchitecture As Language
Architecture As Language
 
Mini Project- Internet Security Mechanisms
Mini Project- Internet Security MechanismsMini Project- Internet Security Mechanisms
Mini Project- Internet Security Mechanisms
 

More from APU

. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientationAPU
 
3. use cases
3. use cases3. use cases
3. use casesAPU
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languagesAPU
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classesAPU
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patternsAPU
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagramsAPU
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using umlAPU
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to umlAPU
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_moduleAPU
 
14 file handling
14 file handling14 file handling
14 file handlingAPU
 
13 gui development
13 gui development13 gui development
13 gui developmentAPU
 
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin javaAPU
 
09 abstract classesandinterfaces
09 abstract classesandinterfaces09 abstract classesandinterfaces
09 abstract classesandinterfacesAPU
 
02 introductionto java
02 introductionto java02 introductionto java
02 introductionto javaAPU
 
12 multi-threading
12 multi-threading12 multi-threading
12 multi-threadingAPU
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagramsAPU
 
4.class diagramsusinguml
4.class diagramsusinguml4.class diagramsusinguml
4.class diagramsusingumlAPU
 
Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)APU
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)APU
 

More from APU (19)

. 1. introduction to object orientation
. 1. introduction to object orientation. 1. introduction to object orientation
. 1. introduction to object orientation
 
3. use cases
3. use cases3. use cases
3. use cases
 
. 9. oo languages
. 9. oo languages. 9. oo languages
. 9. oo languages
 
08 aggregation and collection classes
08  aggregation and collection classes08  aggregation and collection classes
08 aggregation and collection classes
 
. 8. design patterns
. 8. design patterns. 8. design patterns
. 8. design patterns
 
. 5. state diagrams
. 5. state diagrams. 5. state diagrams
. 5. state diagrams
 
. 4. class diagrams using uml
. 4. class diagrams using uml. 4. class diagrams using uml
. 4. class diagrams using uml
 
. 2. introduction to uml
. 2. introduction to uml. 2. introduction to uml
. 2. introduction to uml
 
. 01 introduction_to_module
. 01 introduction_to_module. 01 introduction_to_module
. 01 introduction_to_module
 
14 file handling
14 file handling14 file handling
14 file handling
 
13 gui development
13 gui development13 gui development
13 gui development
 
10 exceptionsin java
10 exceptionsin java10 exceptionsin java
10 exceptionsin java
 
09 abstract classesandinterfaces
09 abstract classesandinterfaces09 abstract classesandinterfaces
09 abstract classesandinterfaces
 
02 introductionto java
02 introductionto java02 introductionto java
02 introductionto java
 
12 multi-threading
12 multi-threading12 multi-threading
12 multi-threading
 
5.state diagrams
5.state diagrams5.state diagrams
5.state diagrams
 
4.class diagramsusinguml
4.class diagramsusinguml4.class diagramsusinguml
4.class diagramsusinguml
 
Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)Design patterns structuralpatterns(thedecoratorpattern)
Design patterns structuralpatterns(thedecoratorpattern)
 
Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)Design patterns structuralpatterns(theadapterpattern)
Design patterns structuralpatterns(theadapterpattern)
 

Design Patterns Chapter Overview

  • 1. Design Patterns Chapter 8 Object-Oriented Software Systems Engineering – Chapter 8 Slide 1
  • 2. Objectives In this chapter we will:  Discuss why software design patterns evolved  Define and describe a software design pattern  Describe fundamental patterns (GRASP patterns) Object-Oriented Software Systems Engineering – Chapter 8 Slide 2
  • 3. Design Patterns – An Introduction  Objectives  Understand why software design patterns evolved  Define and describe a software design pattern  Describe fundamental patterns (GRASP patterns) Object-Oriented Software Systems Engineering – Chapter 8 Slide 3
  • 4. Why patterns?  designing reusable software is hard  novices are overwhelmed  experts draw from experience  some design solutions reoccur  understanding reoccurring solutions is beneficial in several ways Object-Oriented Software Systems Engineering – Chapter 8 Slide 4
  • 5. Why patterns? “Wisdom is often ascribed to those who can tell just the right story at the right moment and who often have a large number of stories to tell.” Robert C. Shank Object-Oriented Software Systems Engineering – Chapter 8 Slide 5
  • 6. What is a pattern? Occurrence  chess from rules to expertise  literature oldest reference  agriculture wisdom vs. science  fishing anecdotal documentation  architecture pioneer work  software design Object-Oriented Software Systems Engineering – Chapter 8 Slide 6
  • 7. Architectural Patterns Light from two sides Place at Window Deep terrace Object-Oriented Software Systems Engineering – Chapter 8 Slide 7
  • 8. What is a pattern? “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.” Alexander et al. Object-Oriented Software Systems Engineering – Chapter 8 Slide 8
  • 9. What is a pattern? Patterns are proven  “Aggressive disregard for originality”  Rule of three “Once is an event, twice is an incident, thrice it's a pattern.” Jerry Weinberg Object-Oriented Software Systems Engineering – Chapter 8 Slide 9
  • 10. The Origins of Design Patterns  They originate from the work of Christopher Alexander, a building architect in the 1970’s.  Alexander’s idea was to improve the quality of the buildings of the time by utilising proven ‘patterns’ of good architectural design.  ‘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.’ Object-Oriented Software Systems Engineering – Chapter 8 Slide 10
  • 11. From Buildings to Software  Alexander’s work ‘discovered’ by Kent Beck and friends in the 1980’s.  They applied Alexander’s ideas about constructing buildings to the building of software.  Patterns are found in all areas of computing, from user interface design, the writing of device drivers to the use of databases. Object-Oriented Software Systems Engineering – Chapter 8 Slide 11
  • 12. What is a software pattern?  proven software practice  piece of literature  building block  possible abstraction levels:  language construct  idiom  design pattern  architectural pattern Object-Oriented Software Systems Engineering – Chapter 8 Slide 12
  • 13. What is a Design Pattern?  A design pattern is defined as ‘ a description of communicating objects and classes that are customised to solve a general design problem in a particular context’.  Patterns capture good design principles and communicate them to others.  Design patterns represent the first legitimate attempt at design reusability. Object-Oriented Software Systems Engineering – Chapter 8 Slide 13
  • 14. What is a software pattern? “A methodology tells you how to write down the decisions you have made. A pattern tells you which decisions to make, when and how to make them, and why they are the right” Beck & Johnson Object-Oriented Software Systems Engineering – Chapter 8 Slide 14
  • 15. GRASP Patterns  General Responsibility Assigning Software Patterns  Five patterns  Expert  Creator  High Cohesion  Low coupling  Controller Object-Oriented Software Systems Engineering – Chapter 8 Slide 15
  • 16. Expert  Expert  Assign responsibility to the information expert Sale date time Product Contains Specification 1..* description Described-by price Sales * UPC LineItem quantity • What about responsibilities for • grandTotal of sale • You also need subtotal for a line item • A method to return the price Object-Oriented Software Systems Engineering – Chapter 8 Slide 16
  • 17. Expert Sale date time total sales() Contains 1..* Product Described-by Specification Sales * LineItem description price quantity UPC subtotal() getPrice()  Benefits  Encapsulation is maintained. Supports low coupling which leads to robust and maintainable systems Object-Oriented Software Systems Engineering – Chapter 8 Slide 17
  • 18. Creator  Creator - Assign class B the responsibility to create an instance of class A if one of the following is true  B aggregates or contains A objects  B records instances of A objects  B closely uses A objects  B has the intializing data that will be passed to A when created  Who should be responsible for creating a SalesLineItem instance? Sale date time Product Contains Specification 1..* description Sales Described-by price * LineItem UPC quantity Object-Oriented Software Systems Engineering – Chapter 8 Slide 18
  • 19. Low Coupling Design 1 makePayment() 1:create() :POST p:Payment 2:addPayment(p) :Sale Design 2 makePayment() 1:makePayment(p) :POST :Sale 1.1create() p:Payment Object-Oriented Software Systems Engineering – Chapter 8 Slide 19
  • 20. High Coupling Design 1 Sale Payment date 1 Paid-by 1 Time amount payment getAmount() 1 totalSales() addPayment(p) Captures makeLineItem(i,q) 1 Post sale.makeLineItem(item,qty) sale endSale() Payment p = new enterItem(item,qty) Payment(cash); makePayment(cash) sale.addPayment(p); Object-Oriented Software Systems Engineering – Chapter 8 Slide 20
  • 21. Low Coupling Design 2 Sale Payment date 1 Paid-by 1 Time amount payment getAmount() 1 totalSales() makeLineItem(i,q) Captures makePayment(cash) 1 Post sale.makeLineItem(item,qty) sale endSale() Payment p = new enterItem(item,qty) Payment(cash) makePayment(cash) sale.makePayment(cash) Object-Oriented Software Systems Engineering – Chapter 8 Slide 21
  • 22. High Cohesion  Same example can be analysed from point of view of high cohesion (functional cohesion)  Design two is better Object-Oriented Software Systems Engineering – Chapter 8 Slide 22
  • 23. Controller  Assign responsibility for handling a system event messages  Usually assigned to a controller  Logically the controller should not be a “window”, “Frame”, “applet”, “application” e.t.c. these classes just handle the events and delegate them to a controller.  In practice view and control may be embedded in a single element known as a UI delegate (MVC architecture)  endSale(), enterItem() & makePayment() are embedded into the POST class Object-Oriented Software Systems Engineering – Chapter 8 Slide 23
  • 24. Design Patterns: Essentials  Patterns are found through trial and error and by observation.  In general a design pattern has four essential elements:  The pattern name  The problem the pattern is used to solve  The solution or template for implementing the pattern  The consequences or results of applying the pattern. Object-Oriented Software Systems Engineering – Chapter 8 Slide 24
  • 25. Patterns in the S/W Development Lifecycle  Design patterns are considered complementary to existing object-oriented methodologies.  Success in using design patterns largely depends in the correct selection of the appropriate pattern.  Knowledge and understanding of the use of existing documented patterns is all important.  Therefore the way patterns are catalogued must be unambiguous and complete. Object-Oriented Software Systems Engineering – Chapter 8 Slide 25
  • 26. The ‘Gang of Four’  The most widely known work on design patterns is that of Gamma, Helm, Johnson and Vlissides . ‘The gang of four’ as they are commonly referred to.  Their book ‘Design Patterns: Elements of Reusable Object-Oriented Software’ was published in 1994.  It contains a description of the concepts of patterns, plus a catalog of 23 design patterns with their full documentation. Object-Oriented Software Systems Engineering – Chapter 8 Slide 26
  • 27. Summary In this chapter we have:  Discussed why software design patterns evolved  Defined and described a software design pattern  Described fundamental patterns (GRASP patterns) Object-Oriented Software Systems Engineering – Chapter 8 Slide 27

Editor's Notes

  1. 1
  2. 3 Whether it has to be accepted or to be changed in the future: Designing reusable software is difficult. There are no hard and fast rules. Experienced designers, however, manage to make good designs. Novices, on the contrary, are not sure which design rule to follow when and do not have a handle to relate problems to solutions. The "secret" of experienced designers is (amongst other secrets) that they can draw from a rich knowledge base of designs that are known to work. An experienced designer knows when a particular solution is applicable, how it is established, and what consequences are implied by its selection
  3. 4 3 Expertise often manifests in being able to tell stories about successful design rather than just reciting good design rules. If a prior experience is understood only in terms of the generalization or principle behind the case, we don't have as many places to put the new case in memory. We can tell people abstract rules of thumb which we have derived from prior experiences, but it is very difficult for other people to learn from these. We have difficulty remembering such abstractions, but we can more easily remember a good story. Stories give life to past experience. Stories make the events in memory memorable to others and to ourselves. This is one of the reasons why people like to tell stories~\\cite{shank90}.
  4. 5 4 When people begin to learn to play chess they first learn all the rules and physical requirements of the game. They learn the names of all the pieces, the way that pieces move move and capture, and the geometry and orientation of the board. At this point, people can play chess, although they will probably not a very good players. But as they progress, they will learn the principles of the game. They learn the value of protecting their pieces, and the relative value of those pieces. They learn the strategic value of the center squares and the power of a threat. They learn how the king can oppose the enemy king and how even one passed pawn can win the game. At this point, people can play a good game of chess. They know how to reason through the game and can recognize ``stupid'' mistakes. However, to become a master of chess, one must study the games of other masters. Buried in those games are patterns that must be understood, memorized, and applied repeatedly until they become second nature. There are thousands upon thousands of these patterns. Opening patterns are so numerous that there are books dedicated to their variations. Midgame patterns and ending patterns are also prevalent, and the master must be familiar with them all. So it is with software. First one learns the rules. The algorithms, data structures and languages of software. At this point, one can write programs, albeit not very good ones. Later, one learns the principles of software design. Structured programming, modular programming, object oriented programming. One learns the the importance of cohesion and coupling, of information hiding and dependency management. But to truly master software design, one must study the designs of other masters. Deep within those designs are patterns that can be used in other designs. Those patterns must be understood, memorized, and applied repeatedly until they become second nature. This chess analogy appears courtesy of Robert C. Martin (rmartin@oma.com).
  5. 6 In architecture there are also rules (e.g., specification of required amount of light in a room) as in software design (e.g., low coupling, high cohesion, number of parameters per method), but in both cases this rules allow to judge an existing configuration but do not generate solutions. Patterns are working solutions and represent solutions that obey design rules and moreover, suggest a specific solution (dining corner with light from three sides, curved entry path). Peter Naur's NATO comment (1968) -- referring to Alexander's “Synthesis of Form” and "Principles of Software Engineering Management" by Tom Gilb (1988) are early software references
  6. 7 6 Expertise often manifests in being able to tell stories about successful design rather than just reciting good design rules.
  7. 8 Ergo, an essential property of a design pattern should be its successful application in several distinct applications
  8. 10 6 Quote from “Patterns generate architecture”, Ecoop ‘94.