Title: Eran Toch
1Spring 2007
Modeling Behavior with UML Sequence Diagrams
- Eran Toch
- http//www.technion.ac.il/erant
2Outline
- Introduction
- Basic notation
- Alternating paths
- Modularity
3Modeling Process
Introduction Basics Alternations Modularity
4Why to Model Behavior?
- How do we use the SMS Server interface? What is
the order of executing the operations? - sendMessage, getStatus, Resend?
- getStatus, sendMessage, checkForMessages?
- When do we use resend?
Introduction Basics Alternations Modularity
5Behavioral Modeling
- Where are people coming from?
- Where are they going?
- How do they move from one space to the other?
Introduction Basics Alternations Modularity
6Behavior Modeling
Sequence Diagrams
Activity Diagrams
State Diagrams
CheckoutManager
Add to cart
Order
message create
In process
Check availability
Order
supplied
message change status
okay
problem
Inventory
Supply Order
Notify User
We will not talk about collaboration diagrams
Introduction Basics Alternations Modularity
7Outline
- Introduction
- Basic elements
- Alternating paths
- Modularity
8Building a Sequence Diagrams
- Sequence diagrams capture the use-case behavior
using the foundation of the classes.
Use Case 1
Class C
Class A
Use Case 3
Use Case 2
Class D
Class B
therefore
Objects
Sequence
messages
Introduction Basics Alternations Modularity
9Sequence Diagrams
- A simple sequence diagram
objects
sd Product Buying
Diagram Name
p Product
ShooppingCart
customer
display()
message
getPrice()
activation (focus of control)
addProduct (p)
checkout ()
Life line
Introduction Basics Alternations Modularity
10Object Control
Illustration
obj2 Class2
obj1 Class1
user
Object Creation
operate()
do ()
create ()
Class3
Return Message
foo()
Messages to self
Object Destruction
Introduction Basics Alternations Modularity
11Corresponding Class Diagram
Illustration
Notice that a dependency exists whenever messages
are passed between instances of the class
Dependencies can be overridden by associations,
aggregations etc.
Introduction Basics Alternations Modularity
12Sequences and Use-Cases
p Product
ShooppingCart
customer
display()
getPrice()
addProduct (p)
checkout ()
create ()
Order
Hidden part
Visible part
Introduction Basics Alternations Modularity
13(No Transcript)
14Full Message Attributes
sequence-expression return-value
message-name (argument-list)
C3.1 res getLocation (fig)
message name
argument list
return value
Introduction Basics Alternations Modularity
15Different Kinds of Messages
Synchronous Message
asynchronous Message
Return Message
Introduction Basics Alternations Modularity
16Synchronous Asynchronous Messages
Example
Example
Nested Flow
Asynchronous Flow
teller
Order
Article
appl
err handl
alarm
getValue
unknown
unknown
ring
price
setID
log
Price need to be finished, before teller can do
another operation (getName)
Ring is executed, while the control flow is
returned to err handle and appl
Introduction Basics Alternations Modularity
17Outline
- Introduction
- Basic elements
- Alternating paths
- Modularity
18Flow Constructs
If
Loop
Else
Repeat
Jump
When we tell a scenario, which types of
alternatives do we need?
Introduction Basics Alternations Modularity
19Options
Example
msg Message
Database
Fragment
opt
Condition
msg.statusconfirmed
archive(msg)
Used for modeling simple optional blocks. Has one
operand no "else" guard.
Do something...
Introduction Basics Alternations Modularity
20Alternatives
msg Message
Database
Admin
alt
Alternative Fragment group
msg.statusconfirmed
archive(msg)
Condition
msg.statuserror
notify(msg.getID())
else
Execution regions. At most one will execute.
wait()
Else condition (optional)
Introduction Basics Alternations Modularity
21Loops
OS
Folder
File
loop
for each Folder
Loop Fragment
Display()
loop
for each File
Condition
Display()
Nested Loop Fragment
Introduction Basics Alternations Modularity
22Breaks
Policy
User
User Manager
isLooged login(name,pass)
If the condition is met, the break fragment is
executed, and the reminder of the sequence is
ignored
break
isLooged
addBadLogin(name)
Do something
Handy in model exception handling
Do something
Introduction Basics Alternations Modularity
23Examples of Guards
- for each Object
- 5
- i1..5
- status okay
- No guard means an infinite loop
Introduction Basics Alternations Modularity
24Outline
- Introduction
- Basic elements
- Alternating paths
- Modularity
25Modularity
We need ways to create modular scenarios
Introduction Basics Alternations Modularity
26Referencing a diagram
Policy
User
User Manager
login(name,pass)
ref
Login Handling(user,pass) bool
Reference Gate
Do something
Do something
Introduction Basics Alternations Modularity
27Referenced Diagram
sd Login Handling
Diagram name
User Manager
UserAccount
loop
Input message
login(name,pass)
for each UserAccount
cName - getUseNamer()
cName - getUseNamer()
Output message
opt
cName name
isInSystem(true)
true
false
Introduction Basics Alternations Modularity
28Parallel Fragments
User
Checkout Handler
Shipping Handler
Transaction Handler
provideDetails()
provideDetails()
performCheckout()
par
Ship(address,products)
chargeMoney(CC,sum)
Introduction Basics Alternations Modularity
29Critical Fragment
- the region is treated atomically by the enclosing
fragment (i.e. parallel fragment) - No other operations can interfere while a
critical region is executed
Introduction Basics Alternations Modularity
30Summary
- Behavior Modeling
- Sequence models interaction
- Language
- Objects lifeline
- Messages
- Alternations
- Loops
- Alternatives
- Modularity
- Referencing
- Parallel
Introduction Basics Alternations Modularity