Larman ch. 151 Interaction Diagram Notation Ch. 15

Preview:

Citation preview

Larman ch. 15 1

Interaction DiagramNotation

Ch. 15

Larman ch. 15 2

Interaction Diagrams

• Illustrates how objects interact via messages• 2 diagram types:

– Sequence Diagram(fence format)

– Collaboration Diagram(graph or network) :ClassAInstance

:ClassBInstance

1: message2()

2: message3()

message1()

:ClassAInstance :ClassBInstance

message2()

message1()

message3()

Larman ch. 15 3

Collaboration Diagram

1: makePayment(cashTendered)

1.1: create(cashTendered)

: Register :Sale

:Payment

makePayment(cashTendered)

creation indicated with a"create" message

direction of message

first message

instance

first internal message

link line

parameter

Larman ch. 15 4

Sequence Diagram

: Register : Sale

makePayment(cashTendered)

makePayment(cashTendered)

: Paymentcreate(cashTendered)

an activation box showingthe focus of control

Larman ch. 15 5

Common interaction Diagram Notation

• Classes and Instances:

Sale :Sale s1: Sale

class instance named instance

Larman ch. 15 6

Common interaction Diagram Notation

• Basic Message Expression Syntax:return := message(parameter : parameterType) : returnType

spec := getProductSpec( id )

spec := getProductSpec( id : ItemID )

spec := getProductSpec( id : ItemID ) : ProductSpecification

Larman ch. 15 7

Basic Collaboration Diagram Notation

• Links:a connection path between two objects

1: makePayment(cashTendered)2: foo()

2.1: bar(): Register :Sale

link line

Larman ch. 15 8

Basic Collaboration Diagram Notation

• Messages:

• Messages to ’self’ or ’this’

1: msg2()2: msg3()3: msg4()

3.1: msg5(): Register :Sale

all messages flow on the same link

msg1()

: Register

msg1()

1: clear()

Larman ch. 15 9

Basic Collaboration Diagram Notation

• Creation of Instances:

1: create(cashier)

: Register :Sale {new}

create message, with optional initializing parameters. This willnormally be interpreted as a constructor call.

«create»1: make(cashier)

: Register :Sale {new}

if an unobvious creation message name is used, themessage may be stereotyped for clarity

Larman ch. 15 10

Basic Collaboration Diagram Notation

• Message number sequencing:

:ClassAmsg1() :ClassB1: msg2()

:ClassC

1.1: msg3()not numbered

legal numbering

Larman ch. 15 11

Basic Collaboration Diagram Notation

• Complex sequence numbering:

;ClassAmsg1() :ClassB1: msg2()

:ClassC

1.1: msg3()

2.1: msg5()

2: msg4()

:ClassD

2.2: msg6()

first second

fourth

sixth

fifth

third

Larman ch. 15 12

Basic Collaboration Diagram Notation

• Conditional Messages:

1 [ color = red ] : calculate(): Foo : Bar

message1()

conditional message, with test

Larman ch. 15 13

Basic Collaboration Diagram Notation

• Mutually Exclusive Conditional Paths:

1a [test1] : msg2()

:ClassA :ClassB

:ClassC

1a.1: msg3()

msg1()

:ClassD

1b [not test1] : msg4()

1b.1: msg5()

:ClassE

2: msg6()

unconditional aftereither msg2 or msg4 1a and 1b are mutually

exclusive conditional paths

Larman ch. 15 14

Basic Collaboration Diagram Notation

• Iteration or Looping:

1 * [i:=1..N]: num := nextInt(): SimulatorrunSimulation() : Random

iteration is indicated with a * and an optionaliteration clause following the sequence number

Larman ch. 15 15

Basic Collaboration Diagram Notation

• Iteration over a Collection:

1 *: st := getSubtotal(): Salet := getTotal()

double box indicates a multiobject (collection)

for example, a List object containing manySalesLineItem objects

*

:SalesLineItem:SalesLineItem

these two * symbols used together implyiteration over the multiobject and sending thegetSubtotal message to each member

Larman ch. 15 16

Basic Collaboration Diagram Notation

• Messages to a Class Object

: Foo

list := synchronizedList( aList )message1()

java.util.Collections

not underlined,therefore a class

message to class, or astatic method call

Larman ch. 15 17

Basic Sequence Diagram Notation

• Links:– Sequence diagrams do not show links (connection

paths between objects)

Larman ch. 15 18

Basic Sequence Diagram Notation

• Messages:

: Register : Sale

msg2()

msg3()

msg1()

msg4()

msg5()

Larman ch. 15 19

Basic Sequence Diagram Notation

• Messages – illustrating returns:

: Register : Sale

msg2()

msg3()

msg1()

msg4()

msg5()

Larman ch. 15 20

Basic Sequence Diagram Notation

• Messages to ’self’ or ’this’:

: Register

msg1()

clear()

Larman ch. 15 21

Basic Sequence Diagram Notation

• Creation of Instances:

: Register : Sale

makePayment(cashTendered)

: Paymentcreate(cashTendered)

authorize()

note that newly createdobjects are placed at theircreation "height"

an object lifeline shows the extent ofthe life of the object in the diagram

Larman ch. 15 22

Basic Sequence Diagram Notation

• Object lifelines and Object Destruction:

: Sale

: Paymentcreate(cashTendered)

...the «destroy» stereotypedmessage, with the largeX and short lifelineindicates explicit objectdestruction

«destroy» X

Larman ch. 15 23

Basic Sequence Diagram Notation

• Conditional Messages:

: Bar: Foo

[ color = red ] calculate()message1()

Larman ch. 15 24

Basic Sequence Diagram Notation

• Mutually Exclusive Conditional Messages:

: B: A

[ x < 10 ] calculate()message1()

: C

[ x > 15 ] calculate()

Larman ch. 15 25

Basic Sequence Diagram Notation

• Iteration for a single message:

: Simulator : Random

* [i:=1..N]: num := nextInt()

runSimulation()

Larman ch. 15 26

Basic Sequence Diagram Notation

• Iteration of a Series of Messages:

: Simulator : Random

hours := nextInt()

runSimulation()

: Programmer

work( hours )

* [i:=1..N]

eat()

Larman ch. 15 27

Basic Sequence Diagram Notation

• Iteration over a Collection:

: Sale

* : st := getSubtotal()

t := getTotal()

:SalesLineItem:SalesLineItem

Larman ch. 15 28

Basic Sequence Diagram Notation

• Messages to Class Objects

: Foo

list := synchronizedList( aList )message1()

java.util.Collections

not underlined,therefore a class

message to class, or astatic method call

Larman ch. 15 29

Interaction DiagramsSummary

Collaboration Diagram

• Graph/network format• Links• Time ordering by

message numbers

Sequence Diagram

• Fence format• No links• Time ordering from top to

bottom• Show the focus of control• May illustrate returns

Recommended