Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Larman capitolo 18
Diagrammi di Interazione
public class A
Illustrano interazioni tra gli oggetti del sistema {
diagrammi di sequenza private B myB = new B();
notazione più ricca
immediatamente chiaro l’ordinamento temporale
public void doOne()
esplicita relazione call-flow
{
diagrammi di comunicazione
myB.doTwo();
libertà di posizionamento
myB.doThree();
possibile rappresentare numerosi oggetti
}
}
:A myB : B doOne
:A
doOne 1: doTwo
doTwo 2: doThree
myB : B
doThree
makePayment(cashTendered)
diagramma
di sequenza makePayment(cashTendered)
create(cashTendered) : Payment
direction of message
makePayment(cashTendered) 1: makePayment(cashTendered)
diagramma di :Register :Sale
comunicazione
1.1: create(cashTendered)
:Payment
Diagrammi di Sequenza
Intestazione delle Linee di Vita
Rappresentano i partecipanti all’interazione
lifeline box representing the class
lifeline box representing a Font, or more precisely, that Font is
lifeline box representing an
named instance an instance of class Class – an
unnamed instance of class Sale
instance of a metaclass
«metaclass»
:Sale s1 : Sale
Font
List is an interface
lifeline box representing an lifeline box representing
instance of an ArrayList class, one instance of class Sale, in UML 1.x we could not use an
parameterized (templatized) to selected from the sales interface here, but in UML 2, this (or
hold Sale objects ArrayList <Sale> collection an abstract class) is legal
sales: x : List
sales[ i ] : Sale
ArrayList<Sale>
related
example
Sintassi per i Messaggi
return = message(parameter:parameterType):returnType
Esempi:
initialize(code)
initialize
d = getProductDescription(id)
d = getProductDescription(id:ItemID)
d = getProductDescription(id:ItemID):ProductDescription
Linee di Vita, Messaggi e Centro di Controllo
: Register : Sale
doX
doA
doB
un messaggio trovato
il cui mittente non è
specificato doC
doD
: Register : Sale
doX
d1 = getDate
getDate
aDate
Messaggi a Self
: Register
doX
clear
Creazioni Istanze
: Register : Sale si noti che i nuovi oggetti
creati sono posizionati alla
“altezza” della loro creazione
makePayment(cashTendered)
create(cashTendered) : Payment
authorize
Distruzione di Oggetti
: Sale
create(cashTendered)
: Payment
Il messaggio stereotipato
... <<destroy>>, con la X
grande e la linea di vita
«destroy» breve, indica l’esplicita
X distruzione dell’oggetto
Messaggi Asincroni
Uso dei Messaggi Asincroni
Frame
:A :B
etichetta guardia makeNewSale
un frame di
ciclo di UML, loop [ more items ]
enterItem(itemID, quantity)
con
un’espressione
booleana di description, total
guardia
region Regione critica che può essere eseguita da un solo thread alla volta
ref Riferimento ad un altro sequence diagram, può includere parametri e valore di ritorno
Frame alt
:A :B :C
doX
alt [ x < 10 ]
calculate
[ else ]
calculate
Frame loop
lineItems[i] :
: Sale This lifeline box represents one
SalesLineItem
instance from a collection of many
t = getTotal SalesLineItem objects.
: Foo : Bar
xx
yy
messaggio condizionale
sintassi semplificata
Frame par
in parallelo
Frame region
regione critica - un solo thread
Frame neg
Frame ref
invocazione di metodo
alternativa semplice
Payment {abstract}
polimorfe CreditPayment
authorize()
...
DebitPayment
authorize()
...
doX
authorize stop at this point – don’t show any
further details for this message
authorize authorize
doA doX
doB
: Foo : Bar
xx
loop(n)
calculate
Diagrammi di Comunicazione
Oggetti
Gli oggetti sono rappresentati come i rettangoli delle linee della vita
«metaclass»
:Sale s1 : Sale
Font
List is an interface
lifeline box representing an lifeline box representing
instance of an ArrayList class, one instance of class Sale, in UML 1.x we could not use an
parameterized (templatized) to selected from the sales interface here, but in UML 2, this (or
hold Sale objects ArrayList <Sale> collection an abstract class) is legal
sales: x : List
sales[ i ] : Sale
ArrayList<Sale>
related
example
Collegamenti
Un collegamento è un percorso di connessione tra due oggetti
(indica quindi una forma di navigazione e visibilità)
1: makePayment(cashTendered)
2: foo
: Register :Sale
2.1: bar
linea di collegamento
Messaggi
numeri di sequenza == ordine dei messaggi nel thread di controllo corrente
solitamente il messaggio iniziale non viene numerato
msg1
1: msg2
2: msg3
3: msg4
: Register :Sale
3.1: msg5
msg1
: Register
1: clear
creare istanze
Three ways to show creation in a
communication diagram
create message, with optional initializing parameters. This will
normally be interpreted as a constructor call.
1: create(cashier)
: Register :Sale
1: create(cashier)
: Register :Sale {new}
«create»
1: make(cashier)
: Register :Sale
msg1 :A 1: msg2 :B
1.1: msg3
2.1: msg5
2: msg4 :C
2.2: msg6
:D
Messaggi Condizionali
message1
non condizionale,
dopo msg2 o msg4 1a e 1b sono percorsi
:E condizionali mutualmente
esclusivi
2: msg6
1a [test1] : msg2
msg1 :A :B
:D 1b.1: msg5 :C
Iterazioni
this iteration and recurrence clause indicates This lifeline box represents one instance from a
we are looping across each element of the collection of many SalesLineItem objects.
lineItems collection.
lineItems[i] is the expression to select one
element from the collection of many
SalesLineItems; the ‘i” value comes from the
message clause.
message to class, or a
static method call
doX
authorize authorize
doA
doX
:DebitPayment doB :Foo :CreditPayment :Bar
3: runFinalization
:ClockStarter System : Class
1: create
asynchronous message
2: run
active object
:Clock
diagramma di interazione e di classe
prodotti in parallelo
: Register : Sale
makePayment(cashTendered)
makePayment(cashTendered)
messages in interaction
diagrams indicate operations
in the class diagrams classes
identified in the
interaction
diagrams are
Register Sale declared in the
1 class diagrams
... ...
currentSale
makePayment(…) makePayment(…)
... ...