UML behavior models

UML behavior models
Kristian Sandahl
2016-09-13
UML/Kristian Sandahl
2
Maintenance
Validate Requirements, Verify Specification
Acceptance Test
Requirements
(Release testing)
Verify System Design
System Design
System Testing
(Architecture,
High-level Design)
(Integration testing of modules)
Module Design
(Program Design,
Detailed Design)
Verify Module Design
Module Testing
(Integration testing of units)
Verify Implementation
Implementation
of Units (classes, procedures,
functions)
Unit testing
Project Management, Software Quality Assurance (SQA), Supporting Tools, Education
2
2016-09-13
UML/Kristian Sandahl
The goals of module design, again
•
Provide the expected function
•
Prepare for change:
•
•
Separation of concern
•
Testability
•
Understandability
Contribute to quality, eg:
•
Performance
•
Usability
•
Reliability
•
•
...
•
Map for the implementers and testers
3
3
Well-known Diagrams of UML
UML/Kristian Sandahl
2016-09-13
4
UML 2.5
Diagram
Structure
Diagram
Class
Diagram
Object
Diagram
Behavior
Diagram
Package
Diagram
Component
Diagram
Deployment
Diagram
4
Use-Case
Diagram
State
Machine
Diagram
Interaction
Diagram
Sequence
Diagram
Well-known Diagrams of UML
UML/Kristian Sandahl
2016-09-13
5
UML 2.5
Diagram
Structure
Diagram
Class
Diagram
Object
Diagram
Behavior
Diagram
Package
Diagram
Component
Diagram
Deployment
Diagram
5
Use-Case
Diagram
State
Machine
Diagram
Interaction
Diagram
Sequence
Diagram
Different instance models
Specific
Kristian :
CoffeeCustomer
Generic
aCoffeeCustomer :
CoffeeCustomer
Short hand
: CoffeeCustomer
Related: Roles
: CoffeeCustomer
buys
buys
buys
buys
Cup1 : CupOfCoffee
aCup : CupOfCoffee
: CupOfCoffee
: CupOfCoffee
6
makes
IDA-B-house :
Machine
makes
aMachine :
Machine
makes
: Machine
makes
: Machine
2016-09-13
UML/Kristian Sandahl
7
State machine diagram
For class
CoinHandler:
start state marker
transiton
checking
this object
falseCoin()/returnCoin(self)
idle
insertCoin()/checkCoin(self)
state
trigger event,
causing transition
action, reaction
to the event
7
2016-09-13
UML/Kristian Sandahl
A few more states
•
•
•
•
8
Kristian’s alarm clock starts sounding at 6.00 with a
nasty signal. He can now do either of three things:
a) Turn the alarm off;
b) Press the snooze button; or
c) Do nothing.
If the snooze button is pressed the signal will turn off and start
sounding after 5 minutes again.
When an hour has passed from the first time the alarm sound
started, the snooze button has no effect.
After that the alarm sound starts, the signal will last for 2 minutes.
If no action has been taken during these 2 minutes, the absence of
action will have the same effect as if the snooze button were pressed
exactly when the alarm stopped to sound.
8
2016-09-13
UML/Kristian Sandahl
Orthogonal, composite states
state machine
course attempt
orthogonal state
Studying
Lab 1
Project
Final exam
fail
orthogonal region
lab1 done
Lab 2
lab2 done
project done
pass
Failed
Passed
9
UML/Kristian Sandahl
Explicit exit points
course attempt
Studying
Lab 1
Project
Final exam
lab1 done
Lab 2
lab2 done
project done
pass
fail
failed
passed
2016-09-13
10
2016-09-13
UML/Kristian Sandahl
Activity diagram ≠ State diagram
Initial node
insert coin
decision
final
[no] node
coin accepted?
fork
[yes]
brew coffee
add hot water
to adjust strength
add sugar/whitener
join
pour coffee
11
2016-09-13
UML/Kristian Sandahl
12
Sequence diagram
role
: Interface
Message
(synchronous)
: CoffeeCustomer
insertCoin
Life line
of object
machineReady
pressButton(b1)
time
pourCoffee
Procedure
is active
2016-09-13
UML/Kristian Sandahl
Sequence diagram with several roles
: Interface
: CoinHandler
: Brewer
: CoffeeCustomer
insertCoin
Timing
constraint
Return message
transport
{ 0 < 5s}
litIndicators
pressButton(b1)
pourCoffee
coinAccepted
makeOrder(o1)
pourCoffee
warmUp
13
2016-09-13
UML/Kristian Sandahl
Combining fragments of sequence diagrams
SD processOrder
:Order
:TicketDB
:Account
create
ref
gate
Get existing customer data
loop
loop
[get next item]
reserve(date,no)
loop condition
add(seats)
answer
destruction
14
2016-09-13
UML/Kristian Sandahl
Combining fragments of sequence diagrams
SD Get existing customer data
:Order
create
:TicketDB
Getdata(c1)
Data(c1)
:Account
15
2016-09-13
UML/Kristian Sandahl
Combining fragments of sequence diagrams
SD processOrder
:Order
:TicketDB
:Account
create
ref
Get existing customer data
loop
loop
[get next item]
reserve(date,no)
loop condition
add(seats)
answer
destruction
16
2016-09-13
UML/Kristian Sandahl
17
More fragments of sequence diagrams
:Order
:TicketDB
loop
[get next item]
reserve(date,no)
alt
[available]
guard condition
nested conditional
add(seats)
alternate branches
reject
[unavailable]
UML/Kristian Sandahl
http://www.uml-diagrams.org
18
2016-09-13
18
UML/Kristian Sandahl
2016-09-13
Lecture exercise
• Create an architecture of a system. Break the system
down in (probably) less than 10 elements. Don’t
forget a little explaining text of what we will see.
Line-and-box is OK.
• Reflect on quality factors. Are they facilitated or
impeded?
• What view do you expose to the reader?
• Create a sequence diagram. Use fragments if it eases
interpretation. Maybe it helps to write the use-cases
first?
19
UML/Kristian Sandahl
www.liu.se