www.ddss.arch.tue.nl 7M822 UML Sequence Diagrams 5 October 2009
Dec 22, 2015
www.ddss.arch.tue.nl
7M822
UML Sequence DiagramsUML Sequence Diagrams
5 October 2009
www.ddss.arch.tue.nl
7M822
UML DiagramsUML Diagrams
• Structure diagram– Class diagram– Object diagram– Component diagram– Deployment diagram– Package diagram
• Behaviour diagram– Use Case diagram– Activity diagram– Interaction diagram
• Sequence diagram• Collaboration diagram
2
www.ddss.arch.tue.nl
7M822
UML DiagramsUML Diagrams
• Structure diagram– Class diagram
– Object diagram
– Component diagram
– Deployment diagram
– Package diagram
• Behaviour diagram– Use Case diagram
– Activity diagram
– Interaction diagram• Sequence diagram• Collaboration diagram
3
www.ddss.arch.tue.nl
7M822
Behaviour modellingBehaviour modelling
• Behaviour models are used to describe the overall behaviour of the system.
• Objects interact to implement behaviour. This interaction can be described in two complementary ways, one of them is centred on individual objects and the other on a collection of cooperating objects.
4
www.ddss.arch.tue.nl
7M822
from: Fowler & ScottUML distilled, 2nd edition.
5
www.ddss.arch.tue.nl
7M822
Interaction diagramsInteraction diagrams
• Interaction diagrams are models that describe how groups of objects collaborate in some behaviour.
• Two kinds of interaction diagrams: – sequence diagrams– collaboration diagrams
6
www.ddss.arch.tue.nl
7M822
from: Fowler & ScottUML distilled, 2nd edition.
7
www.ddss.arch.tue.nl
7M822
Sequence diagramSequence diagram
• A sequence diagram captures the behaviour of a scenario.
• The diagram shows a number of objects and the messages that are passed between these objects within the use case.
• A sequence diagram shows a set of messages arranged in time sequence.
:Inputcontroller :Alarm :Timer :Zoomer
:Person
Wake-up time()
On()
On()
Wake-up Time()
Start()
Start()
Off()Off()
Stop()
It is Time()
Buzz()
StopBuzz()
8
www.ddss.arch.tue.nl
7M822
Concepts sequence diagramsConcepts sequence diagrams
:Computer :PrinterServer :Printer :Queue
Print()
Print (file)()
[printer available] Print (file)()
[printer working] Save (file)()
()
()
()
9
www.ddss.arch.tue.nl
7M822
Concepts sequence diagramsConcepts sequence diagrams
:Computer :PrinterServer :Printer
Print (ps file)()
Print (ps file)()
[no queue] Print (ps file)()
()
()
elementary message activation
synchronic message
return
lifeline
object
control guard
10
www.ddss.arch.tue.nl
7M822
Concepts sequence diagramsConcepts sequence diagrams
:Computer :PrinterServer :Printer
Print (ps file)()
Print (ps file)()
Print (ps file)()
()
()
{ a
b-a < 5 secb
b'-b < 1 secb'
}
constraint
11
www.ddss.arch.tue.nl
7M822
Lifeline & MessagesLifeline & Messages
• The vertical line is called the object’s lifeline. The lifeline represents the object’s life during the interaction.
• Each message is represented by an arrow between the lifelines of two objects.
• The order in which these messages occur is shown top to bottom.
• Each message is labeled at minimum with the message name; also arguments and some control information can be included.
• A self-back is a message that an object sends to itself, by sending the message arrow back to the same lifeline.
12
www.ddss.arch.tue.nl
7M822
Elements sequence diagramsElements sequence diagrams
Object1 Object Lifeline Activation Lifeline
Message() Message()Self back()
Return() Return()
Message()
{}
constraint comment
13
www.ddss.arch.tue.nl
7M822
from: Fowler & ScottUML distilled, 2nd edition.
14
www.ddss.arch.tue.nl
7M822
from: Fowler & ScottUML distilled, 2nd edition.
15
www.ddss.arch.tue.nl
7M822
from: Fowler & ScottUML distilled, 2nd edition.
16
www.ddss.arch.tue.nl
7M822
NS Ticket serviceNS Ticket service
Take ticket
Destination
Traveller
Buy OV ticket
Buy NS ticket
Pay ticket
«extends»
«uses»
17
www.ddss.arch.tue.nl
7M822
Class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’
Class diagram of ‘NS ticket service’ including the classes ‘Ticket’ and ‘Destination’
+create()+payPrice()+printTicket()
-fromStation-toStation-oneWay : Boolean-reduction : Boolean-class-date : Date-price : Currency
Ticket
+validateDestination()+showPrice()
-code-name-distance-base price
Destination
+Print()+checkStatusPrinter()
-statusPrinter
Printer
* 1
18
www.ddss.arch.tue.nl
7M822
NS Ticket machine – use case textNS Ticket machine – use case textUse Case Buy OV Ticket
Actors Traveller
Preconditions Traveller has a valid pass
Description 1. Ticket device expects destination code
2. Traveller enters destination code
3. Extension point: NS ticket
4. Ticket device checks code and calculates the charge. Shows destination code & fare. Activates ticket machine for paying
5. Traveller pays (use case: Pay ticket)
6. Ticket device print and supplies ticket
7. Traveller takes ticket
Extension Destination code = NS station.
3a. Ticket device expects ticket type
3b. Traveller enters Single/Return, Discount Y/N, Class
Exceptions Traveller interrupt the interaction or walk away
Traveller enters an incorrect destination code
Payment is not finished off successful
Result Traveller has ticket.
(NS can look forward to the payment)
19
www.ddss.arch.tue.nl
7M822
Sequence diagram – Buy ticketSequence diagram – Buy ticket:Traveller :Destination :Ticket :Payment :Ticketprinter
Choose Destination()Choose Destination()
Push button()
Perform Payment()
Execute printtask()
Put Ticket()
20
www.ddss.arch.tue.nl
7M822
Elevator ExampleElevator Example
Scenario• User pressed floor button• Elevator system detects floor
button pressed• Elevator moves to floor• Elevator open doors• User gets in and press elevator
button• Elevator moves to required floor• Elevator open doors• User gets out• Elevator close doors
21