SDA-Lect09-Fall2024-Sequence Diagrams
SDA-Lect09-Fall2024-Sequence Diagrams
CS-3004
Lecture#09
UML Artifacts
:A myB:B
do2
do1
do3
Java Code for Interaction Diagrams
7
:A myB:B
do1
do2
do3
E x a m p
l e
public class
Sequence Diagram A { private
B myB = ...;
:Sale
s1:Sale
Java Code:
Sale s1 = …;
sales:ArrayList<Sale>
Java Code:
ArrayList<Sale> sales = …;
sales[i]:Sale
Java Code:
ArrayList<Sale> sales = …;
Sale sale = sales.get(i);
:Sale s1:Sale
sales:ArrayList<Sale> sales[i]:Sale
Sequence Diagram Example
17
Common Notations for UML Interaction
Diagrams - Format for Interaction Messages
“Commonly” Used Grammar:
return = message(parameter:parameterType):returnType
initialize(code)
initialize
d = getProductDescription (id)
d = getProductDescription (id : ItemId)
d = getProductDescription (id : ItemId) : ProductDescription
:Register :Sale
Report()
getDate()
toString()
getRegNo()
Self messages can be modeled using nested
execution specification bars.
UML Sequence Diagrams |
20
log
To show the return value of a message you can
either use the message syntax (A) or use a
message line at the end of an execution
specification bar (B).
:Register :Sale
report
theReport = report
Variant A
:Register :Sale
report
report
theReport
Variant B
Object Instance
Creation
Newly created objects are placed
:Register :Sale
at their creation “height”.
makePayment(cashTendered)
create(cashTendered)
:Payment
authorize
create(cashTendered)
:Payment
...
X
Not strictly required by the UML.
The object destruction notation is also used to mark objects that are no
longer usable.
Invoking Static Methods (Class
Methods)
:Register Calendar
report
locales = getAvailableLocales
:Cashier :System
lineItems[i] :
:Sale
SalesLineItem
t = getTotal
st = getSubTotal
i++
st = getSubTotal
lineItems
= new
ArrayList<SalesLineItem>();
public Money getTotal() {
Money t = new
Money(); Money st =
null;
for (SalesLineItem lineItem : lineItems) {
st = lineItem.getSubtotal();
t.add(st);
}
return t;
}
}
How to model the sending of a message only if
a guard condition matches?
UML Sequence Diagrams |
31
Modeling task: Get the sum of all sales that happened today
after 18:00 o’clock.
Use a UML opt frame to model the sending of
a message if the guard condition matches.
UML Sequence Diagrams |
32
:Register sales[i] : Sale
r=
getTotal(startDate)
Modeling task: Get the sum of all sales that happend today
after 18:00 o’clock.
How to model mutually exclusive alternatives?
UML Sequence Diagrams |
33
[type = CashPayment]
create
:CashPayment
: :System
Cashier
makeNewSale ()
loop [ more
items ] enterItem(itemID,
quantity) 1. makeNewSale()
description, price, total 2. enterItem(itemID, quantity)
3. endSale()
4. makePayment(amount)
endSale
total with
taxes
makePayment(amount
)
change due,
receipt
Domain Model
Process Sale
Summar
y