mapping designs to code larman, chapter 20 cse432 object oriented software engineering

8
Mapping Designs to Mapping Designs to Code Code Larman, Chapter 20 Larman, Chapter 20 CSE432 CSE432 Object Oriented Software Object Oriented Software Engineering Engineering

Upload: aron-wheeler

Post on 28-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

Mapping Designs to Mapping Designs to CodeCode

Larman, Chapter 20Larman, Chapter 20

CSE432CSE432

Object Oriented Software Object Oriented Software EngineeringEngineering

Page 2: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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

Page 3: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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

Page 4: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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

Page 5: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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);}

Page 6: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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?

Page 7: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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

Page 8: Mapping Designs to Code Larman, Chapter 20 CSE432 Object Oriented Software Engineering

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