Object Analysis & Design in the textbook. Introduction to GRASP: Assigning Responsibilities to Objects. Responsibility-Driven Design

Similar documents
17. GRASP: Designing Objects with Responsibilities

GRASP: Patterns for. chapter18

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

Information Expert (or Expert)

COMP 6471 Software Design Methodologies

Responsibilities. Using several specific design principles to guide OO design decisions.

Assigning Responsibilities by Larman

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

GRASP ing at the First 5 Patterns Principles CSSE 574: Session 3, Part 4

Last Time: Object Design. Comp435 Object-Oriented Design. Last Time: Responsibilities. Last Time: Creator. Last Time: The 9 GRASP Patterns

On to Object-oriented Design

Principles of Software Construction: Objects, Design and Concurrency. Object-Oriented Design: Assigning Responsibilities.

Principles of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod

GRASP Design Patterns A.A. 2018/2019

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

References: Applying UML and patterns Craig Larman

Tecniche di Progettazione: Design Patterns

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

Object-Oriented Design

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Patterns and Testing

Object-Oriented Design

VEL TECH HIGH TECH Dr. RANGARAJAN Dr. SAKUNTHALA ENGINEERING COLLEGE UNIT 1 UML DIAGRAMS

Goal: build an object-oriented model of the realworld system (or imaginary world) Slicing the soup: OOA vs. OOD

Constantinos Constantinides Computer Science and Software Engineering Concordia University Montreal, Canada

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

CSSE 374: GRASP ing at the First Five Patterns Principles. Shawn Bohner Office: Moench Room F212 Phone: (812)

Progress Report. Object-Oriented Software Development: Requirements elicitation (ch. 4) and analysis (ch. 5) Object-oriented software development

Software Engineering

From designing to coding

Software Modeling & Analysis

COMP 6471 Software Design Methodologies

Object Oriented Analysis and Design CS6502

ADVANCED SOFTWARE DESIGN LECTURE 4 SOFTWARE ARCHITECTURE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING CS2353-OBJECT ORIENTED ANALYSIS AND DESIGN. Unit-I. Introduction to OOAD

Final Exam CISC 475/675 Fall 2004

Assigning Responsibilities

THE UNIVERSITY OF THE WEST INDIES. Answer ALL questions. Marks for each question are given in the margin. This exam is worth 60 marks

Domain Modeling- 2. Generalization

Mapping Designs to Code

OO Design2. Design Artifacts

From Design Patterns: Elements of Reusable Object Oriented Software. Read the sections corresponding to patterns covered in the following slides.

Final Exam. Final Exam Review. Ch 1: Introduction: Object-oriented analysis, design, implementation. Exam Format

Avancier Methods. Very basic design patterns. It is illegal to copy, share or show this document

CTIS 359 Principles of Software Engineering SOFTWARE DESIGN OO(A)D

Creating Class Definitions from Design Class Diagrams: public class SalesLineItem // Java { private int quantity;

CS6502-OBJECT ORIENTED ANALYSIS AND DESIGN Two Marks Question with Answers Unit-I Introduction to OOAD

GRASP 2. CSC 440: Software Engineering Slide #1

Software Engineering Prof.N.L.Sarda IIT Bombay. Lecture-11 Data Modelling- ER diagrams, Mapping to relational model (Part -II)

Eliminate enterprise software design instability - protect variations! Nickolay Kofanov

4 Software models. often more than what people can handle not necessary to know all details at all times

Relationships amongst Objects

Object-Oriented Design II - GRASP

ROEVER ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY CS2353-OBJECT ORIENTED ANALYSIS AND DESIGN. Unit-I. Introduction to OOAD

Logical Architecture & Design Preliminaries

Designing for Visibility & Mapping to Code CSSE 574: Session 4, Part 3

Object-Oriented Functional Analysis and Design for POS Example

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Domain Model and Domain Modeling

On to Object-oriented Design

CSSE 374: Logical Architecture. Shawn Bohner Office: Moench Room F212 Phone: (812)

Lecture 4: Design Concepts For Responsibility- Driven Design Kenneth M. Anderson January 20, 2005

CS6502- OBJECT ORIENTED ANALYSIS AND DESIGN UNIT I

OBJECT ORIENTED ANALYSIS AND DESIGN SYLLABUS

CS 2340 Objects and Design

Principles of Software Construction: Objects, Design, and Concurrency

Object-Oriented Design and Modeling Using the UML

OODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Design Engineering. Overview

OODP OOAD Session 7a

What is a Model? Copyright hebley & Associates

Software Engineering - I

Four More GRASP Principles CSSE 574: Session 5, Part 2

Domain Engineering And Variability In The Reuse-Driven Software Engineering Business.

Introduction to Software Engineering (2+1 SWS) Winter Term 2009 / 2010 Dr. Michael Eichberg Vertretungsprofessur Software Engineering Department of

Class Diagrams in Analysis

BDSA Introduction to OOAD. Jakob E. Bardram

Domain Modeling. CSSE 574: Week 1, Part 3. Steve Chenoweth Phone: Office (812) Cell (937)

BDSA08 Advanced Architecture

CS342: Software Design. November 21, 2017

SKP Engineering College

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

PROCESSI DI PRODUZIONE E GESTIONE DEL SOFTWARE. Analysis and Design with UML. Paola Turci

Microsoft Retail Management System 1.3 Refreshes, Service Packs, and Hotfixes

Click to Accept & Checkout on Store

Object Oriented. Analysis and Design

18.1 Definitions and General OO Principles

Rakuten.com Merchant Manual

8 Designing classes. Main concepts to be covered. Software changes. Change or die. The Zuul Classes. World of Zuul

Object- Oriented Design with UML and Java Part I: Fundamentals

Premium POS Pizza Order Entry Module. Introduction and Tutorial

Sage 300. Sage CRM 7.3 Integration Upgrade Guide

Design. Eric McCreath

Object-Oriented Design. Module UFC016QM. and Programming. Objects and Classes. O-O Design Unit 2: Faculty of Computing, Engineering

Requirements and Design Overview

Sage 300. Sage CRM 2018 Integration Upgrade Guide. October 2017

Seminar report Software reuse

Lecture 20: Design Patterns II

CHAPTER 9 DESIGN ENGINEERING. Overview

Transcription:

Object Analysis & Design in the textbook Chapter 2 Object Oriented Design Process Introduction to GRASP: Assigning Responsibilities to Objects CS 4354 Summer II 2016 Jill Seaman Much of the material in this lecture is from the Larman book listed on the Readings page (accessible from the class website). There are also links to other (free) presentations and You Tube videos there. Gives good guidelines for identifying and assigning the following: - Classes - attributes - associations, aggregations, inheritance relationships - Good start to a class diagram representing the problem But what about operations? - Sequence diagrams are good tools to explore interactions and operations - But little advice is given on how to decide who does what. 1 2 The design of behavior Responsibility-Driven Design What methods go in what classes? How should objects interact? These are critical questions in the design of behavior. Poor answers lead to abysmal, fragile systems with low reuse and high maintenance. Assigns responsibilities to classes Methods are implemented to fulfill responsibilities of the given class. Methods may act alone or in collaboration to fulfill their obligations. Responsibilities of classes: Knowing: about attributes, related classes, computed values Doing: Calculating, coordinating, creating, controlling Responsibilities come from the use cases: If the system does X, then what class is responsible for carrying out X? 3 4

GRASP Patterns Patterns GRASP General Responsibility Assignment Software Patterns. These are well-known best principles for assigning responsibilities. Nine core principles that object-oriented designers apply when assigning responsibilities to classes and designing message interactions. We will look at 5 of these 9 principles Can be applied during the creation of sequence diagrams, or even during implementation. After or in tandem with developing the class diagrams. Named description of a problem/solution pair that can be applied in new contexts, with advice on how to apply it in novel situations, and discussion of its trade-offs. Notable benefits of patterns: Simplifying: provides a named, generally understood building block - Facilitates communication - Aids thinking about the design Accelerates learning to not have to develop concepts from scratch 5 6 Pattern: Information Expert POS class diagram Problem: What is most basic, general principle of responsibility assignment? Solution: Assign a responsibility to the object that has the information necessary to fulfill it. That which has the information, does the work. In a Point of Sale (think: cash register) application, who should be responsible for knowing the grand total of a sale? By Information Expert we should look for that class that has the information needed to determine the total. It is necessary to know about all the SalesLineItem instances of a sale and the sum of the subtotals. A Sale instance contains these, i.e. it is an information expert for this responsibility. 7 8

POS Information Expert So gettotal will be a method of the Sale class. POS Information Expert What information is needed to determine the line item subtotal? - quantity and price. SalesLineItem should determine the subtotal. This means that Sale needs to send getsubtotal() messages to each of the SalesLineItems and sum the results. 9 10 POS Information Expert POS Information Expert To fulfill the responsibility of knowing and answering its subtotal, a SalesLineItem needs to know the product price. The ProductSpecification is the information expert on answering its price. To fulfill the responsibility of knowing and answering the sale s total, three responsibilities were assigned to three design classes The fulfillment of a responsibility often requires information that is spread across different classes of objects. This implies that there are many partial experts who will collaborate in the task. 11 12

Pattern: Creator POS class diagram Problem: Who should be responsible for creating a new instance of some class? Solution: 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 records instances of A objects. B has the initializing data that will be passed to A when it is created (thus B is an Expert with respect to creating A). The more that are true, the better. In the POS application, who should be responsible for creating a SalesLineItem instance? Since a Sale contains many SalesLineItem objects, the Creator pattern suggests that Sale is a good candidate. 13 14 POS Creator Pattern: Low Coupling This assignment of responsibilities requires that a makelineitem method be defined in Sale. Coupling (in a class diagram) is a measure of how strongly one class is connected to, has knowledge of, or relies on other classes. A class with high coupling depends on many other classes (libraries, tools). Problems because of a design with high coupling: Changes in related classes force local changes. Harder to understand in isolation; need to understand other classes. Harder to reuse because it requires additional presence of other classes. Problem: How to support low dependency, low change impact and increased reuse? Solution: Assign a responsibility so that coupling remains low. 15 16

POS: Low Coupling Which class should be responsible for creating a Payment and associating it with a sale? Since Register records a payment (in real life), it could : Register : Sale be Register, by the Creator pattern create() addpayment( p ) p : Payment Register could then send an addpayment message to Sale, passing along the new Payment as a parameter. This assignment of responsibilities couples the Register class to knowledge of the Payment class. POS: Low Coupling An alternative solution is to have the Sale object create the Payment and associate it with the Sale. No coupling between Register and Payment. : Register : Sale create() : Payment 17 18 Pattern: High Cohesion Cohesion (in a class diagram) is a measure of how strongly related and focused the responsibilities of a class are. A class with low cohesion does many unrelated activities or does too much work. Problems because of a design with low cohesion: Hard to understand. Hard to reuse. Hard to maintain. Delicate, affected by change. Problem: How to keep complexity manageable? Solution: Assign a responsibility so that cohesion remains high. POS High Cohesion Let s compare the same two examples as before with respect to cohesion: : Register : Sale create() addpayment( p ) p : Payment Since Register records a payment (in real life), it could be Register, by the Creator pattern Register could then send an addpayment message to Sale, passing along the new Payment as a parameter. Register may become bloated if it is assigned more and more system operations. 19 20

POS: High Cohesion An alternative design delegates the Payment creation responsibility to the Sale, which supports higher cohesion in the Register. No class has too much work (good delegation). This design supports high cohesion and low coupling. : Register : Sale Pattern: Controller What class should handle system event messages (such as input from the user/user interface)? Solution: Choose a class whose name/job suggests: The overall system, device, or subsystem OR, represents the use case scenario or session create() : Payment Recall: MVC architectural pattern: the Controller component 21 22 POS: Controller POS: Controller In this example, the Register object (a controller) handles the input event. In this example, SaleJFrame, a UI object handles the input event presses button : Cashier actionperformed( actionevent ) UI Layer :SaleJFrame system operation message 1: enteritem(itemid, qty) Don t want the UI objects tightly coupled with the internal objects (Sale) Cashier UI Layer presses button :SaleJFrame actionperformed( actionevent ) It is undesirable for an interface layer object such as a window to get involved in deciding how to handle domain processes. Business logic is embedded in the presentation layer, which is not useful. controller Domain Layer :Register 1.1: makelineitem(itemid, qty) :Sale Domain Layer 1: makelineitem(itemid, qty) :Sale 23 SaleJFrame should not send this message. 24

Summary of Introduction to GRASP 5 principles for deciding how to assign responsibility (behavior) to classes: Information Expert Creator Low Coupling Example: Object-Oriented Analysis & GRASP This example is based on the Inventory system described in Assignment 2. I will treat Process Sale as a use case for the Fulfillment Specialist actor. (I m not going to address any other use cases). High Cohesion Controller These decisions can be made When designing the CRC cards When designing the sequence diagrams from the use cases. 25 26 Use Case: Process Sale 1. The Fulfillment Specialist enters the following values: the sku of the sold item, the quantity that were sold, and the cost to ship all of the items. 2. The System finds the Product with the given sku in the Inventory. 3. The System decreases the quantity of the Product by the given quantity that were sold. 4. The System computes the total price, shipping credit, commission, and profit, and outputs these values to the FulfillmentSpecialist. Variation #1. No product with given sku 1.1. Start after Step 1. 1.2. System cannot find Product, System outputs an error message and aborts. Variation #2. Not enough quantity for the sale 2.1. Start after Step 2. 2.2. If the quantity of the Product in the inventory is not greater than the quantity sold, System outputs an error message and aborts. Class diagram with attributes, associations The Product price is needed to compute the desired statistics The Product qty will be updated by the use case. 27 28

Sequence diagram for process sale, v.1 Forwards engineering (this is not like the code I wrote). Driver does all the work (low coherence, bad) d:driver Sequence diagram for process sale, v.2 Now the Driver dispatches the work to Inventory and Product. The Product has all the information to compute the statistics, so now it calculates the statistics (by Information Expert) d:driver But what about coupling? 29 30 Sequence diagram for process sale, v.3 Now the Driver dispatches the work to Inventory, who delegates to the Product. Low coupling, high cohesion, and information expert is applied Add operations to class diagram searchlist can be private now (and returns Product) d:driver 31 32

Explain GRASPatterns used Inventory.processSale(sku,qty,c): By high cohesion, Inventory should be responsible to process the sale (so the Driver doesn t have to do all of it). Product.processSale(qty,c): By information expert, Product has the information needed to compute the statistics (and update the quantity) so it will do that work. Inventory.processSale(sku,qty,c): By low coupling, Inventory should find the product AND send the processsale message to it (so the Driver doesn t have to talk to the Product). 33