mapping designs to code larman, chapter 20 cse432 object oriented software engineering
TRANSCRIPT
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 Create methods from Interaction
diagramsdiagrams
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 : Textprice : MoneyitemID : ItemID
...
1
description
Fig. 20.1Fig. 20.1
From Interaction diagram to From Interaction diagram to methodmethod
Fig. 20.4Fig. 20.4
2: makeLineItem(desc, qty)enterItem(id, qty)
1: desc := getProductDescription(id)
:Register :Sale
:ProductCatalog
{ ProductDescription desc = catalog.ProductDescription(id); currentSale.makeLineItem(desc, qty);}
Collection classesCollection classes
SalesLineItem
quantity : Integer
getSubtotal()1..*
Sale
isComplete : Booleantime : 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 In UML, exceptions can be inserted as property strings of messagesas property strings of messages
Why implement from least-Why implement from least-coupled coupled
to most-coupled?to most-coupled?
SalesLineItem
quantity : Integer
getSubtotal()
ProductCatalog
...
getProductDesc(...)
ProductDescription
description : Textprice : MoneyitemID : ItemID
...
Store
address : Addressname : Text
addSale(...)
Payment
amount : Money
...
1..*
1..*
Register
...
endSale()enterItem(...)makeNewSale()makePayment(...)
Sale
isComplete : Booleantime : DateTime
becomeComplete()makeLineItem(...)makePayment(...)getTotal()...
1
1
1
1
1
1
* 1
23
4
56
7
Fig. 20.7Fig. 20.7