0% found this document useful (0 votes)
23 views38 pages

SDA-Lect09-Fall2024-Sequence Diagrams

adasdasd

Uploaded by

i210423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views38 pages

SDA-Lect09-Fall2024-Sequence Diagrams

adasdasd

Uploaded by

i210423
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Software Design and Analysis

CS-3004
Lecture#09

Dr. Javaria Imtiaz,


Mr. Basharat Hussain,
Mr. Majid Hussain
Quiz 03
Revision up till now

UML Artifacts

Set of Use Case High-Level System Sequence Sequence


and Domain Model Diagram Diagram
Requirements Diagram
Expanded
Use cases
Visual Representation
Use case Identification
Visual
• Domain Conceptual Classes Visual
• System as a • System as a
Main Success white box
of Requirements in the• form of Use Case Scenarios Representation
• Attributes Blackbox
Representation
• System events
Non-Functional Functional Boss test • Relationship between conceptual
Requirements Diagram
Requirements • Elementary Business Process
Domain
classes each Use Case
• Size Test • Cardinality

⮚ Represent feature/functions/user goals


⮚ Presented as VERB
UML
Interaction
• UML Sequence Diagrams
Diagrams
Sequence Diagram

• Sequence diagram simply depicts interaction between


objects in a sequential order (i.e. the order in which these
interactions take place.)

• Sequence diagrams describe how and in what order the


objects in a system function
Sequence Diagram

They illustrate how the different parts of a system interact


with each other to carry out a function, and the order in
which the interactions occur when a particular use case is
executed
3

Interaction diagrams are used to visualize the interaction


via messages between objects; they are used for
dynamic object modeling.
Example
Example of Sequence Diagram

: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 = ...;

public void do1()


{ myB.do2();
myB.do3();
}
}
Common Notations for UML Interaction Diagrams

:Sale

Lifeline box representing an unnamed instance of class Sale.


Common Notations for UML Interaction Diagrams

s1:Sale

Java Code:
Sale s1 = …;

Lifeline box representing a named instance (s1) of Sale.


Common Notations for UML Interaction Diagrams

sales:ArrayList<Sale>

Java Code:
ArrayList<Sale> sales = …;

Lifeline box representing an instance of an ArrayList class,


parameterized to hold Sale objects.
Common Notations for UML Interaction Diagrams

sales[i]:Sale

Java Code:

ArrayList<Sale> sales = …;
Sale sale = sales.get(i);

Lifeline box representing one instance of class Sale, selected from


the sales ArrayList<Sale> collection.
Common Notations for UML Interaction Diagrams

: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

Parentheses are usually excluded if there are no parameters.


Type information may be excluded if unimportant.

initialize(code)
initialize
d = getProductDescription (id)
d = getProductDescription (id : ItemId)
d = getProductDescription (id : ItemId) : ProductDescription

The same syntax is used by, e.g., the Scala programming


language.
UML Sequence
Diagrams
Modeling (Synchronous)
Messages
UML Sequence Diagrams
| 18

a found message whose sender typical synchronous message


will not be specified shown with a filled-arrow
line

:Register :Sale
Report()
getDate()

execution specification bar


indicates focus of control

toString()

getRegNo()
Self messages can be modeled using nested
execution specification bars.
UML Sequence Diagrams |
20

:Register self message


cancelTransaction

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

The name create is an UML idiom; it is not required.


Object Instance
Destruction
:Register :Sale
makePayment(cashTendered)

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

public class Register {


public void
report() {
Locale[] locales = Calendar.getAvailableLocales();
}
}

Corresponding Java Code


Diagram frames in UML sequence diagrams are
used to support - among others - conditional and
looping constructs.

:Cashier :System

loop [more items] enterItem(itemId, quantity)

description, price, total


How to model the iteration over a collection?

Modeling task: Calculate the total of a sale by summing up the


sub totals for each sales line item.
Use a UML loop frame to iterate over a collection.

lineItems[i] :
:Sale
SalesLineItem
t = getTotal

loop [0 < i < lineItems.size]

st = getSubTotal

i++

Modeling task: Calculate the total of a sale by summing up the


sub totals for each sales line item.
Use a UML loop frame to iterate over a collection.
UML Sequence Diagrams
| 29

:Sale lineItems[i] : SalesLineItem


t = getTotal

loop [for each sales line item]

st = getSubTotal

Modeling task: Calculate the total of a sale by summing up the


sub totals for each sales line item.
Java code corresponding to a UML loop frame.
UML Sequence Diagrams
| 30

:Sale lineItems[i] : SalesLineItem


t = getTotal
public class
Sale { loop [for each sales line item]

private List<SalesLineItem> 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)

loop [for each sale]


date = getDate

opt [startDate < date]


t = getTotal

Frames can be nested.

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

Modeling task: A register should be able to handle credit card


payments and cash payments.
Use the UML alt frame to model between 2 and
n mutually exclusive alternatives.
UML Sequence Diagrams |
34
:Register
makePayment(type,sale)

alt [type = CreditCardPayment]


create
:CreditCardPayment

[type = CashPayment]

create
:CashPayment

Modeling task: A register should be able to handle credit card


payments and cash payments.
Process Sale Scenario

: :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

The goal of this lecture is to enable you to


systematically carry out small(er) software
projects that produce quality software.
• Modeling the dynamic behavior is often more rewarding than modeling
the static structure w.r.t. understanding a domain
• Modeling the dynamic behavior is often particularly useful if the control-
flow is more involved; but only draw the part that is relevant to
understand the problem at hand
• The UML is often used informally - this is OK if everyone interprets the
diagrams in the same way

You might also like