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

Similar documents
Mapping Designs to Code

OO Design2. Design Artifacts

COMP 6471 Software Design Methodologies

Some Software Engineering Techniques (Class Diagrams and Pair Programming)

Download FirstOODesignPractice from SVN. A Software Engineering Technique: (Class Diagrams)

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

Information Expert (or Expert)

From designing to coding

References: Applying UML and patterns Craig Larman

Software Modeling & Analysis

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

What is a Model? Copyright hebley & Associates

Operations Contracts and Preliminaries on Design

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

Logical Architecture & Design Preliminaries

SE203b: OO Design for Software Engineers. Office: TEB349, Ext

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

ADVANCED SOFTWARE DESIGN LECTURE 7 GRASP

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

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

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

CSSE 374: Design Class Diagrams. Shawn Bohner Office: Moench Room F212 Phone: (812)

Sequence Diagram. A UML diagram used to show how objects interact. Example:

COMP 354: INTRODUCTION TO SOFTWARE ENGINEERING

Design Engineering. Overview

Applying UML & Patterns (3 rd ed.) Chapter 15

Domain Modeling: Associations and Attributes

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

On to Object-oriented Design

Sequence Diagram. r: Register s: Sale

Modeling Dynamic Behavior

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

Assigning Responsibilities by Larman

GRASP: Patterns for. chapter18

Chapter 3: Object Oriented Design

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

Chapter 15 UML Interaction Diagrams. Larman, C. Applying UML and Patterns. 3rd Ed. Ed. Prentice-Hall: 2005.

PART 5 Elaboration Iteration 3 Intermediate topics. Iteration 3

Modeling Dynamic Behavior

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

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

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

Design. Furthermore, it is natural to discover and change some requirements during the design and implementation work of the early iterations.

Domain Modeling- 2. Generalization

REPRESENTATION OF CLASS DIAGRAM AND SEQUENCE DIAGRAM IN PROCESS MODELING: UML-BASED STUDY

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

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

Applying Some More Gang of Four Design Patterns CSSE 574: Session 5, Part 4

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

1B1b Classes in Java Part I

More Object Design with GoF Patterns CSSE 574: Session 7, Part 2

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

COMP 6471 Software Design Methodologies

And Even More and More C++ Fundamentals of Computer Science

Introduction to Programming Using Java (98-388)

Notes on Chapter Three

GRASP Design Patterns A.A. 2018/2019

Chapter 6 Introduction to Defining Classes

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

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

CS100J, Fall 2003 Preparing for Prelim 1: Monday, 29 Sept., 7:30 9:00PM

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

Today s Agenda. Quick Review

CSE 142 Wi03 Midterm 2 Sample Solution All Versions Page 1 of 6

Constants, References

Persistence Frameworks with GoF Patterns (State & Command) CSSE 574: Session 7, Part 4

Com S 227 Spring 2018 Topics and review problems for Exam 1 Monday, February 19, 6:45 pm Exam locations by last name:

UML Behavioral Models

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Defining Classes. Chap 1 introduced many concepts informally, in this chapter we will be more formal in defining

On to Object-oriented Design

Understanding class definitions

EECS168 Exam 3 Review

On to Iteration 3, and Activity Diagrams CSSE 574: Session 6, Part 1

More Object Design with GoF Patterns (continued) CSSE 574: Session 7, Part 3

Domain Model and Domain Modeling

Array. Prepared By - Rifat Shahriyar

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

APS101- Midterm Sample Questions

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

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

Software Systems Development Unit AS1: Introduction to Object Oriented Development

Chapter 10 Object-Oriented Design Principles

Understanding class definitions. Looking inside classes (based on lecture slides by Barnes and Kölling)

Ticket Machine Project(s)

BDSA08 Advanced Architecture

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Today s lecture. CS 314 fall 01 C++ 1, page 1

Chapter 4 Defining Classes I

Frequently Asked Questions

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

ECE 122. Engineering Problem Solving with Java

Documenting Advanced Programming Techniques

C++ (Non for C Programmer) (BT307) 40 Hours

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on:

Java Object Oriented Design. CSC207 Fall 2014

JAVA MOCK TEST JAVA MOCK TEST II

Transcription:

Designing for Visibility & Mapping to Code CSSE 574: Session 4, Part 3 Steve Chenoweth Phone: Office (812) 877-8974 Cell (937) 657-3885 Email: chenowet@rose-hulman.edu

Agenda Designing for Visibility Mapping Designs to Code Visibility How the drive back to TH felt after class Wed, 12-15-2010. From http://www.hydrometeoindustry.or g/catalogue/productsheets/vaisala /RoadWeather/VaisalaRoadWeathe rsheet.htm.

Visibility An object B is visible to an object A if A can send a message to B Related to, but not the same as: Scope Access restrictions (public, private, etc.) What are four common ways that B can be visible to A?

Attribute Visibility Object A has attribute visibility to object B if A has an attribute that stores B Quite permanent Most common class Register { private ProductCatalog catalog; } enteritem (itemid, quantity) : Register desc = getproductdesc( itemid ) : ProductCatalog public void enteritem( itemid, qty ) { desc = catalog.getproductdesc(itemid) }

Parameter Visibility Object A has parameter visibility to object B if B is passed in as an argument to a method of A Not permanent, disappears when method ends Second most common Methods often convert parameter visibility to attribute visibility enteritem(id, qty) :Register 2: makelineitem(desc, qty) :Sale 1: desc = getproductdesc(id) 2.1: create(desc, qty) Register has methodreturn visibility to ProductDescription :Product Catalog makelineitem(productdescription desc, int qty) { sl = new SalesLineItem(desc, qty); } sl : SalesLineItem

Local Visibility Object A has local visibility to object B if B is referenced by a local variable in a method of A Not permanent, disappears when leaving variable s scope Third most common Methods often convert local visibility to attribute visibility

Global Visibility Object A has global visibility to object B if B is stored in a global variable accessible from A Very permanent Least common (but highest coupling risk)

Cartoon of the Day Used with permission. http://notinventedhe.re/on/2009-9-23

Before we get into Code Created Domain Model from requirements and use cases Used System Sequence Diagrams to identify system operations Clarified system operations with Operation Contracts Depending on the system, many of these steps might just be sketches! Assigned doing responsibilities with Interaction Diagrams (Communication and Sequence Diagrams) Assigned knowing responsibilities with Design Class Diagrams

Moving from Design to Code Design provides starting point for Coding DCDs contain class or interface names, superclasses, method signatures, and simple attributes Two primary tasks 1. Define classes & interfaces 2. Define methods Elaborate from associations to add reference attributes 10

Example: Defining Register Class public class Register { private ProductCatalog catalog; private Sale currentsale; public Register(ProductCatalog pc) {} public void endsale() {} public void enteritem(itemid id, int qty) {} public void makenewsale() {} public void makepayment(money cashtendered) {} } catalog 1 ProductCatalog getproductdesc() Register endsale() enteritem(id: ItemID, qty : Integer) makenewsale() makepayment(cashtendered : Money) currentsale 1 Sale iscomplete : Boolean time : DateTime becomecomplete() makelineitem() makepayment() gettotal() 11

Create Class Definitions from DCDs

Create Methods from Interaction Diagrams

Collections public class Sale { private List<SalesLineItem> lineitems = new ArrayList<SalesLineItem>(); } Guideline: If an object implements an interface, use the interface type for the variable.

What Order? Typically, least coupled to most coupled. Why?

Parameter Visibility Converted to Attribute Visibility enteritem(id, qty) :Register 2: makelineitem(desc, qty) :Sale 2: desc = getproductdesc(id) :Product Catalog 2.1: create(desc, qty // initializing method (e.g., a Java constructor) SalesLineItem(ProductDescription desc, int qty) { description = desc; // parameter to attribute visibility } sl : SalesLineItem SalesLineItem has association with ProductDescription 16

Local Visibility: Register Assigns Method Return to A Local Variable enteritem(id, qty) { // local visibility via assignment of returning object ProductDescription desc = catalog.getproductdes(id); } enteritem (itemid, quantity) : Register desc = getproductdesc( itemid ) : ProductCatalog Register has local visibility to ProductDescription 17

Mapping from Class Diagram to Code Constructor usually not Shown on diagram public class SalesLineItem { private int quantity; private ProductDescription description; public SalesLineItem(ProductDescription desc, int qty) { } public Money getsubtotal() { } } SalesLineItem quantity : Integer getsubtotal() : Money description 1 ProductDescription description : Text price : Money itemid : ItemID 18

Reference Attributes and Role Names Reference Attributes are indicated by associations and navigability in a class diagram Example: A product specification reference on a Sales Line Item SalesLineItem productspec Described-by productspec Product Specification Description 19

Consider enteritem() System Operation enteritem(id, qty) :Register 2: makelineitem(desc, qty) :Sale 1: desc = getproductdesc(id) 2.1: create(desc, qty) :Product Catalog 1.1: desc = get(id) 2.2: add(sl) sl: SalesLineItem : Map<ProductDescription> lineitems : List<SalesLineItem> 20

Dynamic View: enteritem() Communication Diagram by Controller by Creator enteritem(id, qty) 2: makelineitem(desc, qty) :Register :Sale 1: desc = getproductdesc(id) 2.1: create(desc, qty) by Expert :Product Catalog 1.1: desc = get(id) 2.2: add(sl) sl: SalesLineItem : Map<ProductDescription> lineitems : List<SalesLineItem> add the newly created SalesLineItem instance to the List Why choice of Map for ProdDesc and List for SaleLineItems? 21

Mapping Messages to Methods { } ProductDescription desc = catalog.productdescription(id); currentsale.makelineitem(desc, qty); enteritem(id, qty) :Register 2: makelineitem(desc, qty) :Sale 1: desc := getproductdescription(id) :Product Catalog Each message maps to a method call within enteritem() 22

Adding Collection from 1 to Many Association public class Sale { private List lineitems = new ArrayList(); } Declared as List not ArrayList! Interface type Is more generic Sale iscomplete : Boolean time : DateTime becomecomplete() makelineitem() makepayment() getttotal() A collection class is necessary to maintain attribute visibility to all the SalesLineItems. lineitems 1..* SalesLineItem quantity : Integer getsubtotal() 23

Implementing Methods from IDs { } lineitems.add( new SalesLineItem(desc, qty) ); enteritem(id, qty) 2: makelineitem(desc, qty) :Register 2.2: add(sl) :Sale 2.1: create(desc, qty) lineitems : List<SalesLineItem> sl: SalesLineItem Sale.makeLineItem(), part of the enteritem() interaction diagram Notice how simply the method can be implemented! 24

Implementing Classes in Order Store 7 address : Address name : Text addsale() 1 1 ProductCatalog getproductdesc() 3 1..* ProductDescription description : Text price : Money itemid : ItemID 2 1 Register endsale() enteritem() makenewsale() makepayment() 6 1 Sale iscomplete : Boolean time : DateTime becomecomplete() makelineitem() makepayment() gettotal() * 5 1..* 1 SalesLineItem quantity : Integer getsubtotal() Payment 1 4 1 amount : Money 25

Working Example: PM 26

PM: Use Case Diagram 27

PM: Class Diagram 28

PM: Class to Code class WorkPackage; class Project; class Activity; class Task; class WorkProduct; class Resource; class Skill; class ResourceXSkill; 29

PM: Class to Code class WorkPackage { // Details omitted }; class Project : public WorkPackage { private: CollectionByVal<Activity> theactivity; }; class Activity : public WorkPackage { private: Project *theproject; CollectionByVal<Task> thetask; CollectionByRef<WorkProduct> theworkproduct; }; 30

PM: DCD Mapping 31

PM: DCD Code class Project { private: char *Name; char *Descr; Date StartDate; static int NumberOfProjects; public: Project (char *Name); Project (void); ~Project (void); char *getname (void); void setname (char *thename); void setdescr (char *Descr); char *getdescr (void); void setstartdate (Date thestartdate); Date getstartdate (void); void addactivity (const Activity &theactivity); CollectionByRef<Activity> getallacitivities (void); static int getnumberofprojects (void); void save (void); void load (char *Name); protected: bool hasactivities (void); }; int Project::NumberOfProjects = 0; 32

PM: Sequence Diagram 33