Mapping Designs to Mapping Designs to
CodeCode
Larman, Chapter 20Larman, Chapter 20
CSE432CSE432
Object Oriented Software Object Oriented Software
EngineeringEngineering
OO development is iterativeOO development is iterative
OOA/D artifacts feed into implementation OOA/D artifacts feed into implementation
model in a traceable mannermodel in a traceable manner
Some tools generate partial code from UMLSome tools generate partial code from UML
But programming not trivial generation!But programming not trivial generation!
Programmers make changes as the work Programmers make changes as the work
out the detailsout the details
Therefore, Expect and plan for change and Therefore, Expect and plan for change and
deviation from design during programmingdeviation from design during programming
Mapping Designs to CodeMapping Designs to Code
Write source code for:Write source code for:
–Class and interface definitionsClass and interface definitions
–Method definitionsMethod definitions
Work from OOA/D artifactsWork from OOA/D artifacts
–Create class definitions for Domain Class Create class definitions for Domain Class
Diagrams (DCDs)Diagrams (DCDs)
–Create methods from Interaction diagramsCreate methods from Interaction diagrams
From DCD to Java classFrom DCD to Java class
public class SalesLineItem
{
private int quantity;
private ProductDescription description;
public SalesLineItem(ProductDescription desc, int qty) { ... }
public Money getSubtotal() { ... }
}
SalesLineItem
quantity : Integer
getSubtotal() : Money
ProductDescription
description : Text
price : Money
itemID : ItemID
...
1
description
Fig. 20.1Fig. 20.1
Collection classesCollection classes
SalesLineItem
quantity : Integer
getSubtotal()
1..*
Sale
isComplete : Boolean
time : DateTime
becomeComplete()
makeLineItem()
makePayment()
getTtotal()
public class Sale
{
...
private List lineItems = new ArrayList();
}
A collection class is necessary to
maintain attribute visibility to all the
SalesLineItems.
lineItems
Fig. 20.5Fig. 20.5
What collection class has been added to the design and why?
Exception handlingException handling
Why is it wise to consider large-scale Why is it wise to consider large-scale
exception handling strategies during exception handling strategies during
design modeling?design modeling?
In UML, exceptions can be inserted as In UML, exceptions can be inserted as
property strings of messagesproperty strings of messages
Why implement from least-coupled Why implement from least-coupled
to most-coupled?to most-coupled?
SalesLineItem
quantity : Integer
getSubtotal()
ProductCatalog
...
getProductDesc(...)
ProductDescription
description : Text
price : Money
itemID : ItemID
...
Store
address : Address
name : Text
addSale(...)
Payment
amount : Money
...
1..*
1..*
Register
...
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
Sale
isComplete : Boolean
time : DateTime
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
...
1
1
1
1
1
1
*
1
2
3
4
5
6
7
Fig. 20.7Fig. 20.7