Object-Oriented Analysis and Design

Slides:



Advertisements
Similar presentations
Chapter 7 System Models.
Advertisements

Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
Week 2 The Object-Oriented Approach to Requirements
Configuration management
OOAD – Dr. A. Alghamdi Mastering Object-Oriented Analysis and Design with UML Module 3: Requirements Overview Module 3 - Requirements Overview.
Systems Analysis and Design with UML Version 2.0, Second Edition
Chapter 11 Component-Level Design
From Model-based to Model-driven Design of User Interfaces.
Object Design Examples with GRASP
Object-Oriented Analysis and Design CHAPTER 17, 25: GRASP PATTERNS 1.
Object-Oriented Analysis and Design CHAPTERS 12-14: INTRODUCTION TO DESIGN 1.
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.
February Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Pronunciation: -"fi-z&m.
Object-Oriented Analysis and Design
GRASP : Designing Objects with Responsibilities
Fall 2009ACS-3913 Ron McFadyen1 From the Merriam-Webster’s online dictionary ( Main Entry: an·thro·po·mor·phism Date: 1753 an interpretation.
Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative Development Part III Elaboration Iteration I – Basic1.
GRASP Design Patterns: Designing Objects with Responsibilities
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.
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.
Chandan Rupakheti Office: Moench Room F203 Phone: (812) These slides and others derived from Shawn Bohner, Curt.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
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 )
1 Ch 18. Object Design Examples With Grasp Objectives Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to illustrate.
Chapter 7: Object Design Examples with GRASP. Objective Design use case realizations. Apply GRASP to assign responsibilities to classes. Apply UML to.
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.
Object-Oriented Analysis and Design Mar 2, 2009.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
GRASP: Designing Objects With Responsibilities
Object Design Examples with GRASP (Ch. 18)
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.
Object-Oriented Design Part 2
GRASP: Designing Objects with Responsibilities
NJIT UML Class Diagrams Chapter 16 Applying UML and Patterns Craig Larman.
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)
DOMAIN MODEL: ADDING ATTRIBUTES Identify attributes in a domain model. Distinguish between correct and incorrect attributes.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
Object-Oriented Analysis and Design Mar 9, 2008.
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.
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
OO Methodology Elaboration Phase Iteration 1- Part 3.
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.
OO Methodology Elaboration Phase Iteration 1- Part 2.
Elaboration: Iteration 2. Elaboration: Iteration 2 Basics Iteration 1 ends with : All the software has been tested: The idea in the UP is to do early,
Object Design Examples with GRASP
GRASP – Designing Objects with Responsibilities
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
Apply Expert, Creator, Controller, Low Coupling, High Cohesion
GRASP : Designing Objects with Responsibilities
GRASP Design Patterns: Designing Objects with Responsibilities
Object Oriented System Design Responsibilities
Presentation transcript:

Object-Oriented Analysis and Design Chapter 17: GRASP principles

What will we learn? GRASP – Designing objects with responsibilities We will enter the design phase: We’ll learn how to take the analysis we’ve done and convert it to an object-oriented design Recall what we’ve done so far: Explored Use Cases, and how to create Explored how to create a Domain Model after the use cases were created Explored how to create System Sequence Diagrams if necessary, and create Operations Contracts On to the design …

Object Design: Principles Several of the artifacts that were created during analysis stage (Inception, Elaboration phases) provide input into the design: Use case text explain the behavior that software classes must ultimately support. This part of the design is called use case realization, because the design will ultimately “realize” the use cases The SSDs describe the system event/operation messages (at a high level), and this is the starting point for our eventual interaction diagrams We may have Operations Contracts that complement the use case text, to clarify that the software must achieve in a system operation The Supplementary Specification captured any non-functional requirements The Glossary would capture any requirements related to parameters or data, plus other details The Domain Model suggests some names and attributes for our software objects, but at a high level

Object Design: How to Proceed First step is usually a “modeling day”, where time is spent creating UML diagrams for the design model based upon the previously mentioned artifacts The key idea is responsibility-driven design, which is essentially assigning responsibilities to collaborating objects Will result in both static and dynamic diagrams, i.e. class and interaction diagrams Small groups will work on various parts of the design, but shortly after (perhaps a one-day modeling workshop) the team will start coding Remember, this is an iterative approach, not Waterfall! Outputs include UML diagrams for object design (class diagrams), interaction diagrams, package diagrams, user interface sketches (and prototypes), database models, etc.

Responsibility Driven Design (RDD) Basic idea is to assign responsibilities to the software objects Two basic types of responsibility: Doing and Knowing Doing: doing something, creating an object, doing a calculation, initiate some action in another object, control activity between objects. Generate some activity Knowing: knowing about private encapsulated data, related objects, or things that can be derived or calculated May also have Collaboration, in which an object may collaborate with several other objects to fulfill a responsibility Note that responsibilities are not methods – they are an abstraction – but methods fulfill responsibilities RDD leads to thinking of the system as a community of collaborating objects, each with a set of responsibilities

GRASP GRASP = General Responsibility Assignment Software Patterns (or Principles) GRASP names and describes basic principles to assign responsibilities – useful tool for RDD Provides patterns for assigning responsibilities What is a pattern? A principle or idiom used that provide guidance in the creation of software They have a name, describe a problem, and a solution to the problem Patterns can be applied in various circumstances, to numerous contexts Often these guide the assignment of responsibilities to objects A good pattern is a named and well known problem/solution pair that can be applied in new contexts Naming is important – provides a way to identify the pattern Good patterns are usually the result of tried-and-true knowledge, i.e. solutions that have been applied many times before

Gang of Four In 1994, four authors produced a book called Design Patterns Gamma, Helm, Johnson, Vlissides Described 23 patterns that are useful for OOD Considered the “bible” of design pattern books Often referred to as “Gang of Four” patterns, or GoF Patterns We’ll see more in later chapters We will call the GRASP ideas principles and the GoF ideas patterns GRASP principles are more high level, general principles of object design GoF patterns are more concrete, solutions to specific problems in object design

More on GRASP GRASP defines 9 principles These are basic building blocks in OOD Creator Controller Information Expert Low Coupling High Cohesion Polymorphism Pure Fabrication Indirection Protected Variations

Creator Problem: Who should be responsible for creating a new instance of some class? Basic problem in design, so it’s a good idea to have a general principle for deciding how to solve this (i.e., how to assign this responsibility) Solution: Assign class B the responsibility to create class A if one or more of the following is true: B “contains” or completely aggregates A B records A B closely uses A B has the initializing data for A that will be passed to A when it is created (B is an Expert with respect to creating A) Example: Consider the Monopoly Game example. Who creates the Square object?

Creator First, note that this is a Domain Model, not a class diagram – how do we get to the software classes? Look to the Domain Model for inspiration on what the software objects should be Notice that the Board conceptual class contains Squares – this suggests a software class composition Board should create Squares, Squares are part of the Board, Board manages their creation and destruction (composition) After reviewing the Domain Model diagram, we can conclude that a Board object would be a good creator for the Square object in our Design Model Note we also include an interaction diagram, so we can create the dynamic object model along with the static object model

Dog Grooming Parlor Recall that in our Dog Grooming example, we originally had the following in our domain model: Dog Customer owns 1 1 … n

Dog Grooming Parlor Since the dog is really the important element here, we could redesign this as follows: Dog Owner Owned by 1 1 … n In this sense, the Owner information is actually an attribute of the Dog Class This is a decision that will affect how the record is stored, but also creation. If we think of these classes as data classes, the Dog class will create the Owner instance and contain it by Creator Probably better to do the other way around – dogs have many similar names, hard to uniquely identify!

Information Expert Problem: What is a basic principle for assigning responsibilities to objects? Solution: Assign a responsibility to the class that has the information needed to fulfill it. Example: Consider the Monopoly game. Suppose an object wants to reference an Square, given its name. Who is responsible for knowing the Square, given its name? Most likely candidate is the Board, because it is composed of Squares Since the Board is composed of Squares, it is the object that is best suited to produce a particular square given the square’s name – the Board is the Information Expert, it has all of the information needed to fulfill this responsibility See the next slide for how this translates into object design …

Information Expert: Example POS In the Nextgen POS, some class needs to know the grand total of a sale Who is responsible for the total amount of the sale? Using the Expert pattern, the question is: Which object has the information needed to determine the total? Do we look in the Design Model or the Domain Model? Depends – check Design Model if there is enough work done and relevant classes exist, otherwise go to Domain Model For POS, we only have Domain Model (just starting Design) What information do we need to compute the grand total? SalesLineItems instances and their subtotals. Sale object contains these, so it is a good candidate We then create a new object in the Design Model called Sale, add a method to handle this responsibility

Information Expert: Example POS (cont) This is fine, but the total amount is composed of the sum of the line item amounts. Who determines these? How do we determine the line item total? We need to know the quantity being purchased, and the price of the item The SalesLineItem is the best candidate – it would have the quantity and is associated with the Product Description in the Domain Model, so it can find the price We can now use this analysis to build interactions and new classes in the Design Model: We have determined that we need Sale, SalesLineItem, and ProductDescription classes in the Design Model We have also concluded that the Sale object is responsible for computing the total sale amount, the SalesLineItem object is responsible for computing the line item sub-total amount, and the ProductDescription object must make the price of the product visible From here, we add the following to the Design Model:

Information Expert: How to Use Think of the objects in your design model as workers that you manage If you have a task to assign (a responsibility), who do you give it to? You give it to the person that has the best knowledge to do the task Occasionally the knowledge to do the task is spread over several objects Interact via several messages to do the work, but there is usually one object responsible for the completion of the task

Low Coupling Problem: How to support low dependency, low change impact, and increased reuse in your design? Solution: Assign responsibilities so that coupling remains low Coupling is a measure of how strongly one element is connected to, has knowledge of, or relies on other elements. Low coupling means less dependence on other objects This makes sense – if a class with strong coupling is changed, it will affect many other classes, which makes for high change impact Consider the Monopoly Game: We assigned the getSquare responsibility to the Board, because it contains the Squares. What if we assigned it to another class, like “Dog”? Consider the following diagrams – we have increased the coupling in our design, not a good idea

Low Coupling: Monopoly Example Note this adds another layer of complexity to the design model: First, Dog must get a list of all of the Squares from Board Only then can it access the Square it wants to satisfy the responsibility of finding the Square instance given its name Increased coupling – now both Dog and Board are associated with Square Interaction diagram is a clue that this is not a good way to go … Note that this is closely related to the Expert pattern Usually, the Expert is the best choice to fill the responsibility, because using another object will add coupling (the alternate object choice would probably need to be associated with the expert anyway)

Low Coupling: POS Example Suppose we are working on the design model for the NextGen POS, and we have defined three classes: Payment, Register, and Sale. Suppose we have assigned the responsibility of makePayment to the Register class, and we determined that a Payment instance needs to be created and then associated with a Sale Which class should do this, to support low coupling? Option 1: We could assume that Register creates the Payment, and then adds the Payment to the Sale with a new method Option 2: We could have the Register request the Sale to create the Payment Note that Option 2 supports low coupling (see next diagram), so in terms of just low coupling Option 2 would be preferred

Low Coupling: Observations Always good to reduce coupling in design decisions, but can’t be the single factor In coding, coupling could mean: Having an attribute that refers to an instance of another object Calling services or methods of another object Referring to an instance of another object in a method Direct or indirect subclass Using an interface Low coupling is good – independent objects lessen impact of change

Takeaways from Chapter 17 We’ve seen the following GRASP patterns: Creator Information Expert Low Coupling Understand them and why they are used

Next … More GRASP: General Responsibility Assignment Software Patterns Read Chapters 17 and 25