GRASP: Designing Objects with Responsibilities

Slides:



Advertisements
Similar presentations
GRASP: Designing Objects with Responsibilities
Advertisements

Object-Oriented Analysis and Design
Object Design Examples with GRASP
Chapter 22 Object-Oriented Systems Analysis and Design and UML Systems Analysis and Design Kendall and Kendall Fifth Edition.
Chapter 1 Object Oriented Analysis and Design. UML, Patterns, and Object-Oriented Analysis and Design  The essential skills for the creation of well-designed,
Object-Oriented Analysis and Design CHAPTERS 12-14: INTRODUCTION TO DESIGN 1.
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:
Copyright W. Howden1 Lecture 6: Design Evaluation and Intro to OO Design Patterns.
© 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.
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
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.
Fall 2009ACS-3913 Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Date: 1753 an interpretation.
Feb 4, Ron McFadyen1 founded on principles of good OO design idea was first put forth by Christopher Alexander (1977) in their work concerning.
The chapter will address the following questions:
GRASP Design Patterns: Designing Objects with Responsibilities
The Design Discipline.
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 17. GRASP General Responsibility Assignment Software Patterns (Principles) OOD: after identifying requirements, create domain model, define responsiblities.
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
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.
BTS430 Systems Analysis and Design using UML Design Patterns.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
GRASP: Designing Objects With Responsibilities Chapter 17 Applying UML and Patterns -Craig Larman.
GRASP: Designing Objects With Responsibilities
Object-Oriented Analysis and Design Mar 11, 2008.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
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
Copyright © Craig Larman All Rights Reserved Responsibility-Driven Design with the GRASP Patterns.
Systems Analysis and Design in a Changing World, 3rd Edition
Requirements as Usecases Capturing the REQUIREMENT ANALYSIS DESIGN IMPLEMENTATION TEST.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
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.
Patterns Roberto Damiani Mendes. Roteiro Definition; Definition; Architecture Patterns; Architecture Patterns; Design Patterns; Design Patterns; GRASP.
TK2023 Object-Oriented Software Engineering CHAPTER 12 Introduction to Responsibility-Driven Design.
OO Design Roshan Chitrakar. Analysis to Design Do the RIGHT thing Do the RIGHT thing Requirement Analysis Requirement Analysis Domain Modeling with addition.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
GRASP: Designing Objects With Responsibilities
Chapter 17 Designing with Responsibilities. Fig
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.
OO Methodology Elaboration Phase Iteration 1- Part 2.
TK2023 Object-Oriented Software Engineering CHAPTER 13d GRASP Patterns: High Cohesion.
TK2023 Object-Oriented Software Engineering
GRASP – Designing Objects with Responsibilities
Chapter 12: Collaboration Diagram - PART2
Conception OBJET GRASP Patterns
DESIGN MODEL: USE-CASE REALIZATIONS WITH GRASP PATTERNS
TK2023 Object-Oriented Software Engineering
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
GRASP : Designing Objects with Responsibilities
Introduction to Design Patterns Part 1
Object Oriented System Design Responsibilities
Presentation transcript:

GRASP: Designing Objects with Responsibilities Chapter 17 Applying UML and Patterns Craig Larman

GRASP : Designing Objects With Responsibilities Learning aid to help understand essential object design Apply design reasoning in a methodical, rational, explainable way

Design Activities During design and coding we apply various OO design principles, among them software design patterns such as the GRASP and GoF (Gang of Four) patterns. Our metaphor is Responsibility Driven Design (RDD), because our chief design emphasis is on assigning responsibilities to objects.

Design Model Relationships Domain Model Business Model Requirements Some object names and attributes Use Case Model Glossary Supplementary Specification System Sequence Diagram Item details Domain rules Non-func reqs Events and functional requirements Interaction Diagrams Design

Responsibilities and Methods Responsibilities are realized as methods Approach to understanding and using design principles is based on patterns of assigning responsibilities. Definition of Responsibility: “A contract or obligation of a classifier” Responsibility types are Knowing or Doing

Responsibilities and interaction diagrams Interaction diagrams show choices in assigning responsibilities to objects. Decisions in responsibility assignment are reflected in the messages sent to different classes of objects

Patterns Principles and idioms codified in a structured format describing the problem, solution, and given a name are called patterns. A “New Pattern” is an oxymoron. Patterns are tried and true, established ways of doing things. They are not new things or new ways of doing things.

Definition of a Pattern Pattern is a named problem/solution pair that can be applied in new contexts, Includes advice on how to apply it in novel situations and discussion of its trade-offs.

Naming Patterns All Patterns have suggestive names. Naming a pattern, technique, or a principle has the following advantages : It supports chunking and incorporating that concept into our understanding and memory It facilitates communication

GRASP Name chosen to suggest importance of grasping principles to successfully design object-oriented software It is an acronym for General Responsibility Assignment Software Patterns Describes fundamental principles of object design and responsibility assignment, expressed as patterns

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

UML Class diagram notation Three sections: Class Name attributes methods Third section is for methods

Creator Pattern Problem: Who should be responsible for creating a new instance of some class ? Object creation is one of the most common activities in an object-oriented system. It is useful to have a general principle for assignment of creation responsibilities. Supports low coupling, increased clarity, encapsulation, and reusability.

Solution to Creator Problem Assign class B the responsibility to create an instance of class A if one or more of the following is true : B aggregates A objects . B contains A objects. B records instances of A objects. B closely uses A objects. B has the initializing data that will be passed to A when it is created B is a creator of A objects.

Creator Discussion Creator guides assigning responsibilities related to creation of objects, a very common task. Intent is to find a creator that needs to be connected to the created object in any event. Aggregator aggregates Part Container contains Content Recorder records. Sometimes a creator is found by looking for the class that has the initializing data that will be passed in during creation.

Information Expert Pattern Problem: What is a general principle of assigning responsibilities to objects? Solution: Assign a responsibility to the information expert – a class that has the information necessary to fulfill the responsibility Also known as Expert pattern.

Information Expert Discussion A basic guiding principle used continuously in object design. Objects do things related to information they have Often requires information spread across different classes of objects Objects will need to interact via messages to share the work

Contraindications Using Expert Solution suggested by expert may be undesirable, Usually because of problems in coupling and cohesion. Keep the application logic in one place, database in another Rather than intermingling different system concerns in the same component.

Benefits of Using Expert Information encapsulation is maintained Objects use their own information to fulfill tasks. Supports low coupling More robust, maintainable systems Behavior distributed across classes having the required information More cohesive “lightweight” class definitions Easier to understand and maintain. High cohesion is usually supported.

Low Coupling Pattern Coupling is a measure of how strongly one element is connected to, has knowledge of, or relies on other element. Problem: How to support a low dependency, low change impact ,and increased reuse? Solution: Assign a responsibility so that coupling remains low. Is an underlying goal to continually consider

Benefits of Low Coupling Objects are not affected by changes in other components Objects are simple to understand in isolation Objects are convenient to reuse

Controller Pattern A non–user interface object Responsible for receiving or handling a system event Defines methods for system operation.

Controller Problem Problem: Who should be responsible for handling an input system event? Assumes the Model-View-Controller architectural (not software) pattern Separates the user interface (Views) from the functionality of the system Uses controllers to access other functionality (Models).

Controller Solution Solution: Assign the responsibility for receiving or handling a system event message to a class representing either: The overall system, device, or subsystem A use case scenario (or group of use cases) within which the system event occurs

Controller Discussion Controller pattern provides guidance for generally accepted, suitable choices. Often desirable to use the same controller class for all system events of one use case Controller maintains information about the state of the use case

Facade Controller Suitable when there are not “too many” system events Suitable when it is not possible for the user interface (UI) to redirect system event messages to alternating controllers such as in message processing system.

Use–Case controller When placing the responsibilities in a façade controller leads to design with low cohesion or high coupling, Use Case Controller is preferred as an alternative. When there are many system events across different processes; it factors their handling into manageable separate classes.

High Cohesion Pattern Problem: How can complexity be kept manageable? Solution: Assign responsibility so that cohesion remains high Is a measure of how strongly related the responsibilities of something are High Cohesion: An element with highly related responsibilities, which does not do a tremendous amount of work This is an underlying goal to consider constantly.

High Cohesion Benefits Clarity and ease of comprehension of design is increased. Maintenance and enhancements are simplified Low coupling is often supported.

High Cohesion Contraindications Sometimes desirable to create fewer and larger, less cohesive server objects If they provide an interface for many operations

High Cohesion/Low Coupling Low Coupling and High Cohesion go together naturally. One usually leads to the other. Both are outcomes of the OO principle of “chunking,” (aka decomposition) breaking up a large problem into manageable pieces. If the pieces are too simple there will be too many of them. If the pieces are too complex, each will not be understandable.

Varying Degrees of Functional Cohesion Very Low Cohesion – Class is solely responsible for many different functional areas. Low Cohesion – Class has sole responsibility for a complex task in one functional area. Moderate Cohesion – Class has lightweight and sole responsibilities in few areas that are logically related to class concept, but not to each other High Cohesion – Class has moderate responsibilities in one functional area and collaborates with other classes to fulfill tasks.

Summary The skillful assignment of responsibilities is extremely important in object design. Determining the assignment of responsibilities often occurs during the creation of interaction diagrams , and certainly during programming. Patterns are named problem/solution pairs that codify good advice and principles often related to assignment of responsibilities. This lecture has not gone over Larman’s examples in the text of using the GRASP patterns for the POS case study. You need to read that material and understand it thoroughly if you hope to become proficient in applying patterns. It will also take years of using the patterns to become expert with them.