You are on page 1of 22

Interaction Diagrams

❚Collaboration
❚Sequence Diagrams
Interaction Diagrams
❚ Describe a running system
❙ interactions are taking place
❙ messages being passed between objects
❚ Static diagrams such as Class Diagrams
do not show messages
Interactions
❚ To specify an interaction:
❙ messages to be sent
❙ order of the messages
❙ circumstances for sending message
Collaborations
❚ Describe the ways in which objects can be
linked together in order to support the
specified behaviour
❚ Specify objects relevant to a particular
type of interaction
❚ Class diagrams specify all the possible
object structures in a system
Collaborations
❚ Collaborations are not defined in terms of
classes but in terms of the roles that
instances of those classes can play in
various interactions.
Collaboration Diagrams
❚ The example objects are shown as boxes.
❚ Messages are shown as lines between
boxes.
❚ The sequence of messages is indicated
by numbering the messages.
❚ Collaboration diagrams emphasize layout
over sequence.
Example Collaboration Diagram

:Client thePart : Part

theEntry : CatalogueEntry
Classifier Roles
❚ A role describes a particular way in which
an object can participate in an interaction.
❚ A classifier role describes a role that
objects can play in interactions.
The colon
distinguishes a role
from a class
winner : Account

Name of the role Base class


Classifier Roles
❚ Roles often correspond to coherent
subsets of a class's functionality that are
not made explicit on a class diagram.
❙ In a given interaction, an object playing a
particular role will not normally make use of
all the features provided by the base class of
the role
Association Roles
❚ A collaboration consists of a number of
classifier roles connected by association
roles
:Client thePart : Part

Indicate that objects


playing these roles can be theEntry : CatalogueEntry
linked to each other and
exchange messages
Association Roles

CatalogueEntry
queries describes
Client Part Name = “Screw”
Number = 28834
Cost = 0.02
An Example
❚ In a stock control program, an assembly is sent a message
asking it how many parts of a particular type it contains
❚ a client object sending this message might pass the
catalogue entry object representing the part type as a
parameter of the message

:Client a : Assembly
1: count(part)

1.1: number :=getNumber()


<<parameter>>

part : CatalogueEntry
Sequence Diagrams
❚ Collaboration diagrams show classifier
and association roles and superimpose
messages on association roles.
❚ Sequence diagrams show classifier roles
only but make the sequencing of
messages very clear
❚ They provide alternative ways of
expressing the same information.
Sequence Diagrams
❚ Classifier roles are displayed at the top of
the diagram.
❚ The vertical dimension represents time.
❚ Messages are drawn from top to bottom in
the order in which they are sent each role
has a dashed line, called its lifeline,
extending below it.
Sequence Diagrams
❚ The lifeline indicates the period of time
during which objects playing that role
actually exist.
❚ The period of time during which an object
is processing a message is known as an
activation and is represented by a narrow
rectangle whose top is connected to the
message.
Sequence Diagrams
❚ A dashed arrow from the bottom of the
activation rectangle goes back to the
lifeline of the role that sent the message
giving rise to the activation.
Sequence Diagram

:Client a : Assembly part : CatalogueEntry


count(part)
getNumber()

return number
Sequence Diagram
❚ Each message is labeled at minimum with
the message name.
❙ Arguments and control information can also
be included.
❚ A self-call is a message that an object
sends to itself.
❙ Shown by sending the message arrow back
to the same lifeline.
Sequence Diagram
❚ Control information
❙ Condition
❘ Indicates when a message is sent
❘ Message is only sent if the condition is true
❙ Iteration marker
❘ Shows that a message is sent man times to
multiple receiver objects
❘ Shown by an *
Notation of Sequence Diagrams

an OrderEntryWindow an Order an OrderLine

prepare()
object *prepare()

message
iteration
Example Sequence Diagram
an OrderLine a StockItem

condition
hasStock := check()

[hasStock] needsReorder :=
remove() needsToReorder()
Self-call

creation

[hasStock] new a DeliveryItem


Comparing Sequence and
Collaboration Diagrams
❚ Sequence diagrams
❙ Puts the emphasis on sequence
❙ Easy to see the order in which things occur
❚ Collaboration diagrams
❙ Indicate how objects are statically connected

You might also like