Mapping Designs to Code

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

OO Design2. Design Artifacts

COMP 6471 Software Design Methodologies

From designing to coding

Some Software Engineering Techniques (Class Diagrams and Pair Programming)

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

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

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

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

Information Expert (or Expert)

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

References: Applying UML and patterns Craig Larman

Sequence Diagram. r: Register s: Sale

What is a Model? Copyright hebley & Associates

Software Modeling & Analysis

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

Assigning Responsibilities (Patterns of Responsibility Assignment Principles: GRASP)

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

Modeling Dynamic Behavior

On to Object-oriented Design

Assigning Responsibilities by Larman

2 GRASP Patterns and basic OO Design. Roel Wuyts OASS

Modeling Dynamic Behavior

GRASP: Patterns for. chapter18

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

Chapter 3: Object Oriented Design

ADVANCED SOFTWARE DESIGN LECTURE 4 GRASP. Dave Clarke

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

COMP 354: INTRODUCTION TO SOFTWARE ENGINEERING

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

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

PART 5 Elaboration Iteration 3 Intermediate topics. Iteration 3

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

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

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

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

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

Operations Contracts and Preliminaries on Design

COMP 6471 Software Design Methodologies

Understanding class definitions

Design Engineering. Overview

Domain Modeling- 2. Generalization

Today s Agenda. Quick Review

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

Logical Architecture & Design Preliminaries

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

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

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

Domain-Driven Design Activity

On to Object-oriented Design

Domain Modeling: Associations and Attributes

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

Domain Model and Domain Modeling

CHAPTER 7 OBJECTS AND CLASSES

17. GRASP: Designing Objects with Responsibilities

CS 455 Midterm Exam 1 Spring 2011 [Bono] Feb. 17, 2011

Chapter 12: How to Create and Use Classes

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

Objects and State. COMP1400 Week 9. Wednesday, 19 September 12

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

! Two questions when we design an OO system : ! Our Initial goal: learn to design and implement simple objects.

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

Object-Oriented Programming in Java

Ticket Machine Project(s)

Design of Software Systems (Ontwerp van SoftwareSystemen) 2 Basic OO Design. Roel Wuyts

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

Tecniche di Progettazione: Design Patterns

Review. CSE 143 Java. A Magical Strategy. Hash Function Example. Want to implement Sets of objects Want fast contains( ), add( )

Implementation. Learn how to implement the List interface Understand the efficiency trade-offs between the ArrayList and LinkedList implementations

EXAM Computer Science 1 Part 1

Object-oriented basics. Object Class vs object Inheritance Overloading Interface

Computer Sciences 302 Exam 2 Information & Sample Exam

Practice problem on defining and using Class types. Part 4.

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

Course "UML and Design Patterns" of module "Software Engineering and Design", version February 2011 (X)

CHAPTER 7 OBJECTS AND CLASSES

CS 211 Programming Practicum Spring 2018

What is an Iterator? An iterator is an abstract data type that allows us to iterate through the elements of a collection one by one

Subclassing for ADTs Implementation

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

public class TicketMachine Inner part omitted. public class ClassName Fields Constructors Methods

Notes on Chapter Three

Midterm Exam 2 CS 455, Spring 2011

COMP 1006/1406 Assignment 1 Carleton Foodorama (Part 1) Due: Friday, July 14 th 2006, before 11h55 pm

Implementation. (Mapping to Java) Jörg Kienzle & Alfred Strohmeier. COMP-533 Implementation

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS 211 Programming Practicum Spring 2017

Algorithms & Datastructures Laboratory Exercise Sheet 11

Fun facts about recursion

Linked Lists. What Is A Linked List? Example Declarations. An Alternative Collections Data Structure. Head

CSC 222: Object-Oriented Programming. Fall 2017

Programming Problems 22nd Annual Computer Science Programming Contest

Quarter 1 Practice Exam

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

Exam 1 - (20 points)

CSC 222: Object-Oriented Programming. Fall 2015

Outline. iterator review iterator implementation the Java foreach statement testing

Transcription:

Mapping Designs to Code

Creating Class Definitions from DCDs 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...

Creating Methods from Interaction Diagrams (Register.enterItem) ProductDescription desc = catalog.productdescription(id); currentsale.makelineitem(desc, qty); enteritem method of Register

Collections One-to-many relationships are common. For example, a Sale must maintain visibility to a group of many SalesLineItem instances. In OO programming languages, these relationships are usually implemented with the introduction of a collection object, such as a List or Map, or even a simple array. Java libraries contain collection classes such as ArrayList and HashMap, which implement the List and Map interfaces, respectively. The choice of collection class is influenced by the requirements; key-based lookup requires the use of a Map, a growing ordered list requires a List, and so on.

Collections public class Sale... private List lineitems = new ArrayList(); Sale iscomplete : Boolean time : DateTime becomecomplete() makelineitem() makepayment() getttotal() lineitems 1..* SalesLineItem quantity : Integer getsubtotal() A collection class is necessary to maintain attribute visibility to all the SalesLineItems.

Order of Implementation Classes need to be implemented from least-coupled to mostcoupled. E.g., possible first classes to implement are either Payment or ProductDescription; next are classes only dependent on the prior implementations ProductCatalog or SalesLineItem.

Order of Implementation 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...

How to design makenewsale? by Creator and Controller makenewsale :Register create Register creates a Sale by Creator :Sale by Creator, Sale creates an empty collection (such as a List) which will eventually hold SalesLineItem instances create lineitems : List<SalesLineItem> this execution specification is implied to be within the constructor of the Sale instance

enteritem

gettotal

makepayment, getbalance

endsale

Class Payment // all classes are probably in a package named // something like: package com.foo.nextgen.domain; public class Payment private Money amount; public Payment( Money cashtendered ) amount = cashtendered; public Money getamount() return amount;

Class ProductDescription public class ProductDescription private ItemID id; private Money price; private String description; public ProductDescription ( ItemID id, Money price, String description ) this.id = id; this.price = price; this.description = description; public ItemID getitemid() return id; public Money getprice() return price; public String getdescription() return description;

Class ProductCatalog public class ProductCatalog private Map<ItemID, ProductDescription> descriptions = new HashMap()<ItemID, ProductDescription>; public ProductCatalog() // sample data ItemID id1 = new ItemID( 100 ); ItemID id2 = new ItemID( 200 ); Money price = new Money( 3 ); ProductDescription desc; desc = new ProductDescription( id1, price, "product 1" ); descriptions.put( id1, desc ); desc = new ProductDescription( id2, price, "product 2" ); descriptions.put( id2, desc ); public ProductDescription getproductdescription( ItemID id ) return descriptions.get( id );

Class SalesLineItem public class SalesLineItem private ProductDescription description; private int quantity; public SalesLineItem (ProductDescription desc, int quantity ) this.description = desc; this.quantity = quantity; public Money getsubtotal() return description.getprice().times( quantity );

Class Sale public class Sale private List<SalesLineItem> lineitems = new ArrayList()<SalesLineItem>; private Date date = new Date(); private boolean iscomplete = false; private Payment payment; public Money getbalance() return payment.getamount().minus( gettotal() ); public void becomecomplete() iscomplete = true; public boolean iscomplete() return iscomplete; public void makelineitem ( ProductDescription desc, int quantity ) lineitems.add( new SalesLineItem( desc, quantity ) );

public Money gettotal() Money total = new Money(); Money subtotal = null; Class Sale for ( SalesLineItem lineitem : lineitems ) subtotal = lineitem.getsubtotal(); total.add( subtotal ); return total; public void makepayment( Money cashtendered ) payment = new Payment( cashtendered ); //end of sale

public class Register Class Register private ProductCatalog catalog; private Sale currentsale; public Register( ProductCatalog catalog ) this.catalog = catalog; public void makenewsale() currentsale = new Sale(); public void enteritem( ItemID id, int quantity ) ProductDescription desc = catalog.getproductdescription(id); currentsale.makelineitem( desc, quantity ); public void makepayment( Money cashtendered ) currentsale.makepayment( cashtendered ); public void endsale() currentsale.becomecomplete();

Class Store public class Store private ProductCatalog catalog = new ProductCatalog(); private Register register = new Register( catalog ); public Register getregister() return register;