GRASP: Designing Objects with Responsibilities

Slides:



Advertisements
Similar presentations
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Advertisements

GRASP Patterns M Taimoor Khan
Oct 2, Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
Feb R. McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m Function:
Object Oriented Analysis and Design
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
NJIT More GRASP Patterns Chapter 22 Applying UML and Patterns Craig Larman Prepared By: Krishnendu Banerjee.
Fall 2009ACS-3913 Ron McFadyen1 idea was first put forth by Christopher Alexander (1977) in his work on architectural design principles a pattern is a.
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
Creating Architectural Descriptions. Outline Standardizing architectural descriptions: The IEEE has published, “Recommended Practice for Architectural.
Object-Oriented Software Engineering Practical Software Development using UML and Java Design Patterns Sources: Chapter 6: Using Design Patterns, and Chapter.
Low Coupling High Cohesion
NJIT 1 GRASP: Designing Objects with Responsibilities Chapter 17 Applying UML and Patterns Craig Larman.
GRASP : Designing Objects with Responsibilities
October 20, 2005Architectural Design, ECEN Architectural Design Architecture Business Cycle Design for Maintainability ECEN 5543 / CSCI 5548 SW Eng.
CMPT 370: Information Systems Design Instructor: Curtis Cartmill, Simon Fraser University – Summer 2003 Lecture Topic: Layered Architecture Class Exercise:
Design Patterns and Responsibility Assignment CMPT 371 Fall 2004 J.W. Benham.
Fall 2009ACS-3913 Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Date: 1753 an interpretation.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Feb 4, Ron McFadyen1 founded on principles of good OO design idea was first put forth by Christopher Alexander (1977) in their work concerning.
GRASP Design Patterns: Designing Objects with Responsibilities
Chapter 7 GRASP patterns Dr Seham Mostefai CAP 252.
GRASP Pattern Zhen Jiang West Chester University
GRASP Principles. How to Design Objects The hard step: moving from analysis to design How to do it? –Design principles (Larman: “patterns”) – an attempt.
GRASP Patterns Presented By Dr. Shazzad Hosain. Patterns A pattern describes a problem and solution, and given a name. Examples are Singleton, Adapter,
Chapter 18 Object Design Examples with GRASP. Objectives Design use case realizations –A use-case realization describes how a particular use case is realized.
Chapter 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.
1 Chapter 17 GRASP Design Patterns: Designing Objects with Responsibilities.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
Architecture GRASP Realization of use cases in interaction diagrams Design class diagram Design ( how )
Requirements To Design--Iteratively Chapter 12 Applying UML and Patterns Craig Larman.
1 On to Object Design Chapter 14 Applying UML and Patterns.
BTS430 Systems Analysis and Design using UML Design Patterns.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
GRASP: Designing Objects With Responsibilities
Chapter 17 GRASP: Designing Objects with Responsibilities. 1CS6359 Fall 2011 John Cole.
Design Patterns. Patterns “Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Object-Oriented Design Principles and Patterns. © 2005, James R. Vallino2 How Do You Design? What principles guide you when you create a design? What.
Systems Analysis and Design in a Changing World, 3rd Edition
D ESIGN P ATTERNS Weslei A. de T. Marinho. T ALK O UTLINE Pattern Definition GRASP Patterns GoF Patterns GoF Patterns Classification Creational Patterns.
GRASP: Designing Objects with Responsibilities
IntellAgile Copyright © 2002 Craig Larman. All rights reserved. Object Design and Use- Case Realizations with GRASP Patterns.
What to remember from Chap 13 (Logical architecture)
Introduction to Design Patterns Part 1. © Lethbridge/Laganière 2001 Chapter 6: Using design patterns2 Patterns - Architectural Architectural Patterns:
Object-Oriented Analysis and Design Mar 9, 2008.
Design Patterns By Mareck Kortylevitch and Piotreck Ratchinsky.
Patterns Roberto Damiani Mendes. Roteiro Definition; Definition; Architecture Patterns; Architecture Patterns; Design Patterns; Design Patterns; GRASP.
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
References: Applying UML and patterns Craig Larman
Design. 2 The Need for Software Blueprints Knowing an object-oriented language and having access to a library is necessary but not sufficient in order.
General Principles in Assigning Responsibilities Responsibilities Responsibility-Driven Design CRC Cards GRASP.
TK2023 Object-Oriented Software Engineering CHAPTER 13d GRASP Patterns: High Cohesion.
TK2023 Object-Oriented Software Engineering
Object Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
Design Patterns: MORE Examples
TK2023 Object-Oriented Software Engineering
Chapter 12: Collaboration Diagram - PART2
Conception OBJET GRASP Patterns
DESIGN MODEL: USE-CASE REALIZATIONS WITH GRASP PATTERNS
TK2023 Object-Oriented Software Engineering
Presentation on GRASP Patterns Submitted by
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
GRASP : Designing Objects with Responsibilities
GRASP Design Patterns: Designing Objects with Responsibilities
Introduction to Design Patterns Part 1
Object Oriented System Design Responsibilities
Presentation transcript:

GRASP: Designing Objects with Responsibilities Applying UML and Patterns Craig Larman Chapter 17 Glenn D. Blank CSE432, Lehigh University

Chapter Learning Objectives Learn about design patterns Learn how to apply five GRASP patterns You’ve learned about static class diagrams and dynamic interaction diagrams UML is just notation; now you need to learn how to make effective use of the notation UML modeling is an art, guided by principles

Design patterns in architecture A pattern is a recurring solution to a standard problem, in a context. Christopher Alexander, professor of architecture… Why is what a prof of architecture says relevant to software? “A 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.”

Design and dress patterns Jim Coplein, a software engineer: “I like to relate this definition to dress patterns … I could tell you how to make a dress by specifying the route of a scissors through a piece of cloth in terms of angles and lengths of cut. Or, I could give you a pattern. Reading the specification, you would have no idea what was being built or if you had built the right thing when you were finished. The pattern foreshadows the product: it is the rule for making the thing, but it is also, in many respects, the thing itself.”

Patterns in engineering How do other engineers find and use patterns? Mature engineering disciplines have handbooks describing successful solutions to known problems Automobile designers don't design cars from scratch using the laws of physics Instead, they reuse standard designs with successful track records, learning from experience Should software engineers make use of patterns? Why? “Be sure that you make everything according to the pattern I have shown you here on the mountain.” Exodus 25:40. Developing software from scratch is also expensive Patterns support reuse of software architecture design

Definitions and names Alexander: “A pattern is a recurring solution to a standard problem, in a context.” Larman: “In OO design, a pattern is a named description of a problem and solution that can be applied in new contexts; ideally, a pattern advises us on how to apply the solution in varying circumstances and considers the forces and trade-offs.” How is Larman’s definition similar to Alexander’s? How are these definitions significantly different?

Naming Patterns—important! Patterns have suggestive names: Arched Columns Pattern, Easy Toddler Dress Pattern, etc. Why is naming a pattern or principle helpful? It supports chunking and incorporating that concept into our understanding and memory It facilitates communication Star and Plume Quilt

GRASP Name chosen to suggest the importance of grasping fundamental principles to successfully design object-oriented software Acronym for General Responsibility Assignment Software Patterns Describe fundamental principles of object design and responsibility Expressed as patterns

Five GRASP patterns: Creator Information Expert Low Coupling Controller High Cohesion

Creator pattern Name: Creator Problem: Who creates an instance of A? Solution: Assign class B the responsibility to create an instance of class A if one of these is true (the more the better): B contains or aggregates A (in a collection) B records A B closely uses A B has the initializing data for A

Who creates the Squares? Figure 17.3, page 283

How does Create pattern lead to this partial Sequence diagram? Figure 17.4, page 283

How does Create pattern develop this Design Class Diagram (DCD)? Figure 17.5 , page 283 Board has a composite aggregation relationship with Square I.e., Board contains a collection of Squares

Discussion of Creator pattern Responsibilities for object creation are common Connect an object to its creator when: Aggregator aggregates Part Container contains Content Recorder records Initializing data passed in during creation

Contraindications or caveats Creation may require significant complexity: recycling instances for performance reasons conditionally creating instances from a family of similar classes In these instances, other patterns are available… We’ll learn about Factory and other patterns later…

Information Expert pattern or principle Name: Information Expert Problem: How to assign responsibilities to objects? Solution: Assign responsibility to the class that has the information needed to fulfill it? E.g., Board information needed to get a Square

Benefits and Contraindications Facilitates information encapsulation: why? Classes use their own info to fulfill tasks Encourages cohesive, lightweight class definitions But: Information expert may contradict patterns of Low Coupling and High Cohesion Remember separation of concerns principle for large sub-systems I.e., keep “business” or application logic in one place, user interface in other place, database access in another place, etc.

Low Coupling Pattern Name: Low Coupling Problem: How to reduce the impact of change and encourage reuse? Solution: Assign a responsibility so that coupling (linking classes) remains low.

Why does the following design violate Low Coupling? Why is a better idea to leave getSquare responsibility in Board?

Benefits & Contraindications Understandability: Classes are easier to understand in isolation Maintainability: Classes aren’t affected by changes in other components Reusability: easier to grab hold of classes But: Don’t sweat coupling to stable classes (in libraries or pervasive, well-tested classes)

Controller pattern Name: Controller (see Model-View-Controller architecture) Problem: Who should be responsible for UI events? Solution: Assign responsibility for receiving or handling a system event in one of two ways: Represent the overall system (façade pattern) Represent a use case scenario within which the system event occurs (a session controller)

Who is the controller of playGame operation? Figure 17.9, p. 288 What class represents the overall system or relevant use case scenario?

High Cohesion pattern Cohesion measures how strongly related and focused are the responsibilities of an element Name: High Cohesion Problem: How to keep classes focused and manageable? Solution: Assign responsibility so that cohesion remains high.

How does the design on right promote high cohesion? Delegate responsibility & coordinate work

Benefits & Contraindications Understandability, maintainability Complements Low Coupling But: Avoid grouping of responsibilities or code into one class or component to simplify maintenance by one person. Why? Sometimes desirable to create less cohesive server objects that provide an interface for many operations, due to performance needs associated with remote objects and remote communication

Summary Skillful assignment of responsibilities is extremely important in object-oriented design (CRC cards are one technique) Patterns are named problem/solution pairs that codify good advice and principles related to assignment of responsibilities GRASP identifies five patterns or principles: Creator, Information Expert, Controller, Low Coupling and High Cohesion