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

Object Interaction - Sequence Diagrams: Based On Chapter 9 Bennett, Mcrobb and Farmer

Uploaded by

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

Object Interaction - Sequence Diagrams: Based On Chapter 9 Bennett, Mcrobb and Farmer

Uploaded by

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

Object Interaction –

Sequence Diagrams
Based on Chapter 9
Bennett, McRobb and Farmer
Object Oriented Systems Analysis
and Design Using UML
4th Edition, McGraw Hill, 2010
© 2010 Bennett, McRobb and Farmer 1
In This Lecture You Will Learn:
• how to develop object interaction from use
cases;
• how to model object interaction using an
interaction sequence diagram;
• how to cross-check between interaction
diagrams and a class diagram.

© 2010 Bennett, McRobb and Farmer 2


Object Messaging

Objects communicate by sending messages.


Sending the message getCost() to an Advert
object, might use the following syntax.

currentadvertCost = anAdvert.getCost()

:Campaign anAdvert:Advert

getCost

© 2010 Bennett, McRobb and Farmer 3


Equivalent areas of
change—a highly
resilient system.

Application that caters


Real-world for these requirements
requirements
Resilience of A small change in
requirements causes a
Design much greater change in
software—not a resilient
system.

Application that caters


Real-world for these requirements
requirements
© 2010 Bennett, McRobb and Farmer 4
Interaction & Collaboration
• A collaboration is a group of objects or
classes that work together to provide an
element of functionality or behaviour.
• An interaction defines the message
passing between lifelines (e.g. objects)
within the context of a collaboration to
achieve a particular behaviour.

© 2010 Bennett, McRobb and Farmer 5


Modelling Interactions
• Interactions can be modelled using various
notations
– Interaction sequence diagrams
– Communication diagrams
– Interaction overview diagrams
– Timing diagrams

© 2010 Bennett, McRobb and Farmer 6


Sequence Diagrams
• Shows an interaction between lifelines (e.g.
objects) arranged in a time sequence.
• Can be drawn at different levels of detail and to
meet different purposes at several stages in the
development life cycle.
• Typically used to represent the detailed object
interaction that occurs for one use case or for
one operation.

© 2010 Bennett, McRobb and Farmer 7


Sequence Diagrams
• Vertical dimension shows time.
• Objects (or subsystems or other connectable
objects) involved in interaction appear
horizontally across the page and are
represented by lifelines.
• Messages are shown by a solid horizontal arrow.
• The execution or activation of an operation is
shown by a rectangle on the relevant lifeline.

© 2010 Bennett, McRobb and Farmer 8


Sequence diagram
sd Add a new advert to a campaign
Interaction Constraint

Frame label :
CampaignManager :Client :Campaign :Advert
getName

Interaction Operator listCampaigns Combined Fragment


loop [For all client’s campaigns] (loop)
getCampaignDetails

Sequence listAdverts
diagram loop [For all campaign’s adverts]
is enclosed in a getAdvertDetails
frame
addNewAdvert
Advert
newAd:Advert

Lifeline Activation or Execution Object creation

© 2010 Bennett, McRobb and Farmer 9


Sequence Diagram
• Iteration is represented by combined fragment
rectangle with the interaction operator ‘loop’.
• The loop combined fragment only executes if the
guard condition in the interaction constraint
evaluates as true.
• Object creation is shown with the construction
arrow (dashed) going to the object symbol for
the Advert lifeline.

© 2010 Bennett, McRobb and Farmer 10


Synchronous Message
• A synchronous message or procedural call
is shown with a full arrowhead, causes the
invoking operation to suspend execution
until the focus of control has been returned
to it.

© 2010 Bennett, McRobb and Farmer 11


Further Notation

sd Interaction Name
:LifelineA :LifelineB State on lifeline showing
Synchronous pre-condition
(blocking)
message
Receive messaged
Active Event Occurrence
(msg.recieveEvent)
Send message
Event Occurrence msg a start of
(msg.sendEvent) Execution Occurrence

Execution Occurrence

end of
Execution Occurrence
Message reply
showing return of
control

© 2010 Bennett, McRobb and Farmer 12


Boundary & Control Classes
• Most use cases imply at least one boundary
object that manages the dialogue between the
actor and the system – in the next sequence
diagram it is represented by the lifeline
:AddAdvertUI
• The control object is represented by the
lifeline :AddAdvert and this manages the
overall object communication.

© 2010 Bennett, McRobb and Farmer 13


sd Add a new advert to a campaign Control
Boundary lifeline
lifeline :Client :Campaign :Advert
:CampaignManager :AddAdvert

loop [For all clients]


getClient

:AddAdvertUI
startInterface
selectClient showClientCampaigns listCampaigns

loop [For all client’s campaigns]


getCampaignDetails

selectCampaign
showCampaignAdverts
listAdverts
loop [For all campaign’s adverts]
getAdvertDetails

createNewAdvert
addNewAdvert addNewAdvert
Advert
newAd:Advert

© 2010 Bennett, McRobb and Farmer 14


Object Destruction

sd Delete advert

:Campaign :Advert

listAdverts

loop getAdvertDetails

deleteAdvert
delete

Object destruction

© 2010 Bennett, McRobb and Farmer 15


Reflexive Messages
sd Check campaign budget

:
CampaignManager :Client :Campaign :Advert
getName

listCampaigns
loop [For all client’s campaigns]
getCampaignDetails

checkCampaignBudget
loop [For all campaign’s adverts]
getCost Reflexive
message
getOverheads

© 2010 Bennett, McRobb and Farmer 16


Focus of Control
• Indicates times during an activation when
processing is taking place within that object.
• Parts of an activation that are not within the
focus of control represent periods when, for
example, an operation is waiting for a return
from another object.
• May be shown by shading those parts of the
activation rectangle that correspond to active
processing by an operation.

© 2010 Bennett, McRobb and Farmer 17


Focus of Control
sd Check campaign budget

:Client :Campaign :Advert


:
getName
CampaignManager Shading showing the
focus of control
listCampaigns
loop [For all client’s campaigns]
getCampaignDetails

checkCampaignBudget
loop [For all campaign’s adverts]
getCost

getOverheads
Reply with the return-
value shown
budget =
checkCampaignBudget

© 2010 Bennett, McRobb and Farmer 18


Reply Message
• A reply message returns the control to the
object that originated the message that
began the activation.
• Reply messages are shown with a dashed
arrow, but it is optional to show them at all
since it can be assumed that control is
returned to the originating object at the
end of the

© 2010 Bennett, McRobb and Farmer 19


Object Selector Notation
sd Check campaign budget
Object selector notation

: campaign[i] advert[j]
CampaignManager :Client
:Campaign :Advert
getName

listCampaigns Interaction constraint refers


loop [i=1;i<=campaign.count; i++ ] to variable used in object
getCampaignDetails selector notation

checkCampaignBudget

loop [j=1;j<=advert.count; j++ ]


getCost

getOverheads

© 2010 Bennett, McRobb and Farmer 20


Interaction Operators
sd Check campaign budget

: campaign[i] advert[j]
CampaignManager :Client
:Campaign :Advert
getName

listCampaigns
loop (1, *) [i<=campaign.count ]
getCampaignDetails

checkCampaignBudget
loop (1, *) [j<=advert.count ]
getCost
Interaction Operator
with parameters getOverheads

© 2010 Bennett, McRobb and Farmer 21


sd Add a new advert to a campaign if within budget

:
:Client :Campaign :Advert
CampaignManager
getName

listCampaigns ref

List client campaigns

ref
Get campaign budget

addCostedAdvert
alt [totalCost <= budget]
Advert newAd:Advert
alt interaction operator
shows branching
[else]
Request newRequest:Request
Two interaction operands,
one for each alternative

© 2010 Bennett, McRobb and Farmer 22


Handling Complexity
• Complex interactions can be modelled
using various different techniques
– Interaction fragments
– Lifelines for subsystems or groups of objects
– Continuations
– Interaction Overview Diagrams (see later
lecture)

© 2010 Bennett, McRobb and Farmer 23


Using Interaction Fragments
ref interaction operator
indicates interaction
occurrence that
sd Check campaign budget references an interaction
fragment

:
CampaignManager :Client :Campaign :Advert
getName

listCampaigns ref

Gate showing the List client campaigns


message enter this
interaction occurrence

ref

Get campaign budget

© 2010 Bennett, McRobb and Farmer 24


Interaction Fragment
Interaction fragment that is
referenced in
Check campaign budget
sequence diagram

sd List client campaigns

Gate showing the


message enter this
Interaction Fragment :Client :Campaign

listCampaigns
loop [For all client’s campaigns]
getCampaignDetails

© 2010 Bennett, McRobb and Farmer 25


Interaction Fragment
Interaction fragment that is also
referenced in
Check campaign budget
sd Get campaign budget sequence diagram

: :Campaign :Advert
CampaignManager
checkCampaignBudget

loop [For all campaign’s adverts]


getCost

getOverheads

© 2010 Bennett, McRobb and Farmer 26


sd Add a new advert to a campaign

:ClientCampaigns
: :AddAdvert ref ClientCampaignAds
CampaignManager
loop [For all clients]
getClient

:AddAdvertUI
startInterface
selectClient showClientCampaigns listCampaigns

Lifeline representing the


interaction between a
selectCampaign
group of objects
showCampaignAdverts
listAdverts

createNewAdvert
addNewAdvert addNewAdvert

© 2010 Bennett, McRobb and Farmer 27


sd ClientCampaignAds

:Client :Campaign :Advert

getClient

listCampaigns

loop [For all client’s campaigns]


Sequence diagram getCampaignDetails

referenced in the
Add a new advert to listAdverts
a campaign sequence loop [For all campaign’s adverts]
diagram getAdvertDetails

addNewAdvert
Advert newAd:Advert

© 2010 Bennett, McRobb and Farmer 28


Using Continuations
sd Authorize expenditure sd Calculate costs

:LifelineA :LifelineB :LifelineC :LifelineA :LifelineB :LifelineC

getCost
ref
Calculate costs getCost

alt [Within budget]

ref
alt [Within budget] Identify under spend

Within budget
Within budget
authorize
[else] [else]
Budget spent Budget spent
stopExpenditure

Continuations are used to link


sequence diagrams
© 2010 Bennett, McRobb and Farmer 29
Asynchronous Message
• An asynchronous message, drawn with an
open arrowhead, does not cause the
invoking operation to halt execution while
it awaits a return.

© 2010 Bennett, McRobb and Farmer 30


Further Notation
sd Interaction Name

An active :ClassA :ClassB


object

t = now Asynchronous
Time sign
alE message with
constraint {0..1
4} duration
using constraint
construction
marks
signalF
{t..t + 28}
Callback

signal Duration
X d = du
ration observation

{d..d*3}

Y Note explaining some


Duration signal aspect of this
constraint execution occurrence

© 2010 Bennett, McRobb and Farmer 31


Interaction Operators
Interaction Explanation and use
Operator
alt Alternatives represents alternative behaviours, each choice of behaviour being shown in a separate
operand. The operand whose interaction constraint is evaluated as true executes.
opt Option describes a single choice of operand that will only execute if its interaction constraint evaluates
as true.
break Break indicates that the combined fragment is performed instead of the remainder of the enclosing
interaction fragment.
par Parallel indicates that the execution operands in the combined fragment may be merged in any
sequence once the event sequence in each operand is preserved.
seq Weak Sequencing results in the ordering of each operand being maintained but event occurrence from
different operands on different lifelines may occur in any order. The order of event occurrences on
common operands is the same as the order of the operands.
strict Strict Sequencing imposes a strict sequence on execution of the operands but does not apply to nested
fragments.
neg Negative describes an operand that is invalid.

critical Critical Region imposes a constraint on the operand that none of its event occurrences on the lifelines
in the region can be interleaved.
ignore Ignore indicates the message types, specified as parameters, that should be ignored in the interaction.

consider Consider states which messages should be consider in the interaction. This is equivalent to stating that
all others should be ignored.
assert Assertion states that the sequence of messaging in the operand is the only valid continuation.

loop Loop is used to indicate an operand that is repeated a number times until the interaction constraint for
the loop is no longer true.

32
© 2010 Bennett, McRobb and Farmer
Guidelines for Sequence Diagrams
1. Decide at what level you are modelling
the interaction.
2. Identify the main elements involved in
the interaction.
3. Consider the alternative scenarios that
may be needed.
4. Identify the main elements involved in
the interaction.

© 2010 Bennett, McRobb and Farmer 33


Guidelines for Sequence Diagrams
5. Draw the outline structure of the
diagram.
6. Add the detailed interaction.
7. Check for consistency with linked
sequence diagrams and modify as
necessary.
8. Check for consistency with other UML
diagrams or models.

© 2010 Bennett, McRobb and Farmer 34


Model Consistency
• The allocation of operations to objects must be
consistent with the class diagram and the
message signature must match that of the
operation.
– Can be enforced through CASE tools.
• Every sending object must have the object
reference for the destination object.
– Either an association exists between the classes or another
object passes the reference to the sender.
– This issue is key in determining association design (See Ch. 14).
– Message pathways should be carefully analysed.

© 2010 Bennett, McRobb and Farmer 35


Model Consistency
• All forms of interaction diagrams used
should be consistent.
• Messages on interaction diagrams must
be consistent with the state machine for
the participating objects.
• Implicit state changes in interactions
diagrams must be consistent with those
explicitly modelled in state machine.

© 2010 Bennett, McRobb and Farmer 36


Summary
In this lecture you have learned about:
• how to develop object interaction from use
cases;
• how to model object interaction using an
interaction sequence diagram;
• how to cross-check between interaction
diagrams and a class diagram.

© 2010 Bennett, McRobb and Farmer 37


References
• UML Reference Manual (OMG, 2009)
• Bennett, Skelton and Lunn (2005)

(For full bibliographic details, see Bennett,


McRobb and Farmer)

© 2010 Bennett, McRobb and Farmer 38

You might also like