Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 8

Mapping Designs to Code

Larman, Chapter 20
CSE432
Object Oriented Software Engineering
OO development is iterative
 OOA/D artifacts feed into implementation
model in a traceable manner
 Some tools generate partial code from UML
 But programming not trivial generation!
 Programmers make changes as the work
out the details
 Therefore, Expect and plan for change and
deviation from design during programming
Mapping Designs to Code
 Write source code for:
– Class and interface definitions
– Method definitions
 Work from OOA/D artifacts
– Create class definitions for Domain Class
Diagrams (DCDs)
– Create methods from Interaction diagrams
From DCD to Java class
public class SalesLineItem
{
private int quantity;

private ProductDescription description;

public SalesLineItem(ProductDescription desc, int qty) { ... }

public Money getSubtotal() { ... }

ProductDescription
SalesLineItem
description description : Text
quantity : Integer price : Money
1 itemID : ItemID
getSubtotal() : Money
...
Fig. 20.1
From Interaction diagram to method
{
ProductDescription desc = catalog.ProductDescription(id);
currentSale.makeLineItem(desc, qty);
}

enterItem(id, qty) 2: makeLineItem(desc, qty)


:Register :Sale

1: desc := getProductDescription(id)

:Product
Catalog

Fig. 20.4
Collection classes
What collection class has been added to the design and why?

Sale
public class Sale
{ isComplete : Boolean
... time : DateTime SalesLineItem
lineItems
private List lineItems = new ArrayList(); becomeComplete() quantity : Integer
1..*
} makeLineItem()
getSubtotal()
makePayment()
getTtotal()

A collection class is necessary to


maintain attribute visibility to all the
SalesLineItems.

Fig. 20.5
Exception handling
 Why is it wise to consider large-scale
exception handling strategies during
design modeling?
 In UML, exceptions can be inserted as
property strings of messages
Why implement from least-coupled
7
to most-coupled?
Store

address : Address
1 2
name : Text
3 ProductDescription
ProductCatalog
addSale(...)
description : Text
... price : Money
1 1..* itemID : ItemID
getProductDesc(...)
...

1
1 Sale
5
6
Register isComplete : Boolean 4
time : DateTime SalesLineItem
...
becomeComplete() quantity : Integer
endSale() 1 1..*
makeLineItem(...)
enterItem(...) getSubtotal()
makePayment(...)
makeNewSale()
getTotal()
makePayment(...)
...
1
* Payment

amount : Money
1
Fig. 20.7 ...

You might also like