UML - Interaction Diagrams

advertisement
www.ddss.arch.tue.nl
UML Interaction Diagrams
25 November 2010
7M822
www.ddss.arch.tue.nl
UML Views
Component
view
Logical view
Use Case
view
Concurrency
view
Deployment
view
7M822
2
www.ddss.arch.tue.nl
Behaviour 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.
7M822
3
www.ddss.arch.tue.nl
UML Diagrams
• Structure diagram
–
–
–
–
–
Class diagram
Object diagram
Component diagram
Deployment diagram
Package diagram
• Behaviour diagram
– Use Case diagram
– Activity diagram
– Interaction diagram
• Sequence diagram
• Communication diagram
7M822
4
www.ddss.arch.tue.nl
UML Diagrams
• Structure diagram
–
–
–
–
–
Class diagram
Object diagram
Component diagram
Deployment diagram
Package diagram
• Behaviour diagram
– Use Case diagram
– Activity diagram
– Interaction diagram
• Sequence diagram
• Communication diagram
7M822
5
www.ddss.arch.tue.nl
Interactions 1 of 2
• An interaction is a behavior that comprises a set of
messages exchanging among a set of objects with a
context to accomplish a purpose.
• Interactions are used to model the dynamic aspect of
collaborations, representing societies of objects playing
specific roles, all working together to carry out some
behavior that’s bigger than the sum of the elements.
7M822
6
www.ddss.arch.tue.nl
Interactions 2 of 2
• Roles, links, messages, actions, and sequences
• Modeling flows of control
• Each interaction can be modeled in two ways:
– by emphasizing its time ordering of messages, or
– by emphasizing its sequencing of messages
in the context of some structural organization of objects.
7M822
7
www.ddss.arch.tue.nl
In a nutshell: what are interactions?
• A collection of communications between instances,
including all ways to affect instances, like operation
invocation, as well as creation and destruction of
instances
• The communications are partially ordered (in time)
7M822
8
www.ddss.arch.tue.nl
Interaction Diagram Guide
• Show interactions between instances in the model
– graph of instances (possibly including links) and stimuli
– existing instances
– creation and deletion of instances
• Kinds
– Sequence diagram (temporal focus)
– Communication diagram (structural focus)

7M822
9
www.ddss.arch.tue.nl
Interaction Diagrams
Sequence Diagram
x
y
Communication Diagram
z
1.1: a
1.2: c
x
a
y
b
1.1.1: b
c
z
7M822
10
www.ddss.arch.tue.nl
Sequence Diagram
an Order
an Order Line
aProduct
aCustomer
calculatePrice
getQuantity
participant
found
message
lifeline
getProduct
aProduct
getPricingDetails
activation
return
calculateBasePrice
message
self-call
calculateDiscounts
getDiscountInfo
7M822
11
www.ddss.arch.tue.nl
Different Kinds of Arrows
Procedure call or other kind of nested
flow of control (synchronous message)
Return
Asynchronous message
Asynchronous message in UML 1.x
7M822
12
www.ddss.arch.tue.nl
Lifeline & 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.
7M822
13
www.ddss.arch.tue.nl
Communication Diagram
1: calculatePrice
1.5.1: getDiscountInfo
an Order
1.1: getQuantity()
1.2: getProduct()
an Order Line
aCustomer
1.3: getPricingDetails
aProduct
7M822
14
www.ddss.arch.tue.nl
Sequence Diagram / Communication Diagram
an Order
an Order Line
aProduct
aCustomer
1: calculatePrice
calculatePrice
getQuantity
participant
found
message
lifeline
1.5.1: getDiscountInfo
an Order
getProduct
aCustomer
aProduct
getPricingDetails
activation
return
1.1: getQuantity()
1.2: getProduct()
1.3: getPricingDetails
calculateBasePrice
message
self-call
an Order Line
aProduct
calculateDiscounts
getDiscountInfo
7M822
15
www.ddss.arch.tue.nl
Sequence Diagram vs. Communication Diagram
• Sequence diagrams are used when you want to look at
the behavior of several objects within a single use case.
Sequence diagrams are good at showing collaborations
among the objects.
• Communication diagrams emphasize the data links
between the various participants in the interaction.
With communication diagrams we can show how the
participants are linked together.
7M822
16
www.ddss.arch.tue.nl
Elements Sequence Diagrams
Participant
: Object
Participant
/ Object
Lifeline
Message
Return
Activation
Message
Lifeline
Self back
Return
{}
Constraint
Comment
7M822
17
www.ddss.arch.tue.nl
Next Concepts Sequence Diagrams 1of2
:Computer
:PrinterServer
:Printer
:Queue
control guard
Print
Print(file)
[printer available] Print(file)
[printer working] Save(file)
7M822
18
www.ddss.arch.tue.nl
Next Concepts Sequence Diagrams 2of2
:Computer
constraint
:PrinterServer
:Printer
Print
Print(file)
{
Print(file)
a
b-a < 5 sec
b
b'-b < 1 sec
b'
}
7M822
19
www.ddss.arch.tue.nl
Sequence Diagram – an Example
:Inputcontroller
• 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.
:Timer
:Alarm
:Zoomer
:Person
Wake-up time()
Wake-up Time()
On()
On()
Start()
It is Time()
Start()
Buzz()
Off()
Off()
Stop()
StopBuzz()
7M822
20
www.ddss.arch.tue.nl
NS Ticket service
Destination
Buy OV ticket
«extends»
«uses»
Buy NS ticket
Traveller
Pay ticket
Take ticket
7M822
21
www.ddss.arch.tue.nl
Class diagram of ‘NS ticket service’ including
the classes ‘Ticket’ and ‘Destination’
Destination
Ticket
-fromStation
-toStation
-oneWay : Boolean
-reduction : Boolean
-class
-date : Date
-price : Currency
+create()
+payPrice()
+printTicket()
*
1
-code
-name
-distance
-base price
+validateDestination()
+showPrice()
Printer
-statusPrinter
+Print()
+checkStatusPrinter()
7M822
22
www.ddss.arch.tue.nl
NS Ticket machine – use case text
Use Case
Buy OV Ticket
Actors
Traveller
Preconditions
Traveller has a valid pass
Description
1.
2.
3.
4.
5.
6.
7.
Ticket device expects destination code
Traveller enters destination code
Extension point: NS ticket
Ticket device checks code and calculates the charge. Shows destination code & fare.
Activates ticket machine for paying
Traveller pays (use case: Pay ticket)
Ticket device print and supplies ticket
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)
7M822
23
www.ddss.arch.tue.nl
Sequence diagram – Buy ticket
:Traveller
:Destination
:Ticket
:Payment
:Ticketprinter
Choose Destination()
Choose Destination()
Push button()
Perform Payment()
Execute printtask()
Put Ticket()
7M822
24
www.ddss.arch.tue.nl
Elevator 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
7M822
25
Download