You are on page 1of 26

Lab 4:

Interaction diagram
(Sequence diagram)

16-Nov-20 T.A GHADEER AL-HOMYANI 1


Objectives
-To explain what is Interaction Diagram and Sequence Diagram.
-To explain what are the notations involved.

16-Nov-20 T.A GHADEER AL-HOMYANI 2


Introduction
-An interaction is a behavior that comprises a set of messages
exchanging among a set of objects with a context to accomplish a
purpose.

16-Nov-20 T.A GHADEER AL-HOMYANI 3


Type of Interaction Diagram
UML provides four types of interaction diagrams
◦ Sequence diagram - shows objects interacting along lifelines that
represent general order.
◦ Communication diagram - shows the messages passed between
objects, focusing on the internal structure of the objects.
◦ Interaction overview diagram - treats a sequence diagrams as the
unit for a modified activity diagram that does not show any of the
interaction details.
◦ Timing diagram - shows interactions with a precise time axis.

16-Nov-20 T.A GHADEER AL-HOMYANI 4


Sd

-The interaction diagram is displayed with the name of the diagram


shown in a pentagram in the upper-left corner prefixed by sd.

16-Nov-20 T.A GHADEER AL-HOMYANI 5


Sequence diagram

16-Nov-20 6 T.A Ghadeer AL-homyani


Introduction
-Sequence diagrams illustrate how
objects interact with each other.
-Focus on message sequences (how
messages are sent and received between
a number of objects).
-Sequence diagrams have two axes:
◦ vertical axis: shows time
◦ horizontal axis: shows a set of objects.
-A sequence diagram also reveals the
interaction for a specific scenario—a
specific interaction between the objects
that happens at some point in time
during the system’s execution (for
example, when a specific function is
used).
16-Nov-20 T.A GHADEER AL-HOMYANI 7
Introduction (cont.)
-A sequence diagram is enclosed by a rectangular
frame with the name of the diagram shown in a
pentagram in the upper-left corner prefixed by sd.
-On the horizontal axis are the objects involved in the
sequence. Each is represented by an object rectangle
with the object and/or class name underlined.
-The rectangle along with the vertical dashed line,
called the object’s lifeline, indicates the object’s
execution during the sequence (that is, messages sent
or received and the activation of the object).
-Communication between the objects is represented
as horizontal message lines between the objects’
lifelines.
-To read the sequence diagram, start at the top of the
diagram and read down to view the exchange of
messages taking place as time passes.

16-Nov-20 T.A GHADEER AL-HOMYANI 8


Introduction (cont.)
Sequence diagrams can be used in two forms:
◦ instance form - describes a specific scenario in detail; it documents one
possible interaction. The instance form does not have any conditions, branches,
or loops; it shows the interaction for just the chosen scenario.
◦ generic form - describes all possible alternatives in a scenario; therefore
branches, conditions, and loops may be included.

16-Nov-20 T.A GHADEER AL-HOMYANI 9


Lifelines
-Lifeline notation elements are placed across the top of
the diagram.
-Lifelines represent either roles or object instances that
participate in the sequence being modeled.
-Lifelines are drawn as a box with a dashed line
descending from the center of the bottom edge.
-The lifeline's name is placed inside the box.

16-Nov-20 T.A GHADEER AL-HOMYANI 10


Message
-A message is a communication between objects that conveys information with the expectation that action will be
taken.
-The receipt of a message is normally considered an event.
-Messages can be signals, operation invocations, or something similar (for example, remote procedure calls [RPCs]
in C++ or Remote Method Invocation [RMI] in Java).
-When a message is received, an activity starts in the receiving object; this is called execution occurrence.
-An execution occurrence shows the focus of control, which object(s) execute at some point in time. An activated
object is either executing its own code or is waiting for the return of another object to which it has sent a message.
-The execution occurrence is optional on the diagram; when shown it is drawn as a thin rectangle on the object’s
lifeline.
-The messages are shown as arrows between the object lifelines.
-Each message can have a signature with a name and parameters, for example:
print(file:File)

16-Nov-20 T.A GHADEER AL-HOMYANI 11


Message (cont.)
-The messages can also have sequence numbers, though they are not
required because the sequence is given explicitly in the diagram.

16-Nov-20 T.A GHADEER AL-HOMYANI 12


Message (cont.)

16-Nov-20 T.A GHADEER AL-HOMYANI 13


Message (cont.)
-A message can be sent from an object to itself, in which case, the
message symbol is drawn from the object symbol to itself (self-call).
-Two types of message:
◦ Synchronous: associated with an operation, have a send and receive message.
A message is sent from the source lifeline to the target lifeline. The source
lifeline is blocked from other operations until it receives a response from the
target lifeline.
◦ Asynchronous: associated with an operation, typically have only a send
message, but can also have a reply message. In contrast to a synchronous
message, the source lifeline is not blocked from receiving or sending other
messages.

16-Nov-20 T.A GHADEER AL-HOMYANI 14


Concepts summarization

Initialize()

Self-call

Synchronous
message

16-Nov-20 T.A GHADEER AL-HOMYANI 15


Fragments
-Sequence diagrams can be broken up into chunks called fragments.
-A combined fragment encapsulates portions of a sequence diagram.
-These fragments are surrounded by a frame like the one around the whole
diagram; the specifier in the upper-left corner represents an operator that
prescribes how the fragment is handled.
-Within the fragment are one or more operand regions tiled vertically and each
separated by a horizontal dashed line.

16-Nov-20 T.A GHADEER AL-HOMYANI 16


Fragments (Conditional behavior)
-When showing conditional behavior, the interaction operator keyword alt is put
in the pentagram, the fragment is partitioned horizontally with a dashed line
separator, and constraints are shown in square brackets as has been described in
previous sections.
-This fragment with multiple separate flows through it is called a combined
fragment.
-At most one of the alternatives occurs; an else condition can be put on the final
alternative to represent the negation of the disjunction of all other guards.

16-Nov-20 T.A GHADEER AL-HOMYANI 17


Fragments (Conditional behavior)

16-Nov-20 T.A GHADEER AL-HOMYANI 18


Fragments (Loops)
-Loops are designated by placing the interaction operator keyword loop in the
pentagram.
-Textual syntax of the loop operand is “loop [ ‘(‘ <minint> [,<maxint> ] ‘)’ ]” or
a Boolean expression can be placed in the conditional.
-When a loop operator is used, there is no need to separate the rest of the contents
into separate operands; there is no horizontal dashed line.

16-Nov-20 T.A GHADEER AL-HOMYANI 19


Fragments (Loops)

16-Nov-20 T.A GHADEER AL-HOMYANI 20


Interaction Occurences
-It is common to share portions of an interaction between several other
interactions.
-An interaction occurrence allows multiple interactions to reference an
interaction that represents a common portion of their specification.
-When referencing a fragment as an interaction occurrence, the interaction
identifier ref is placed before the name of the fragment.

16-Nov-20 T.A GHADEER AL-HOMYANI 21


Interaction Occurences

Interaction2

16-Nov-20 T.A GHADEER AL-HOMYANI 22


Creating and Destroying Objects
-Sequence diagrams can show how objects are created and destroyed as part of
the scenario documented.
-An object can create another object via a message.
-The object created is drawn with its object symbol placed where it is created (on
the vertical time axis).
-The message that creates the object is shown as a dashed-line, open-headed
arrow.
-When an object is destroyed, it is marked with the stop symbol, a large X; the
destruction is further indicated by drawing the lifeline of that object only to the
point at which it was destroyed.

16-Nov-20 T.A GHADEER AL-HOMYANI 23


Creating and Destroying Objects

16-Nov-20 T.A GHADEER AL-HOMYANI 24


Recursion
-Recursion is a technique used in many algorithms.
-Recursion occurs when an operation calls itself.
-The message (when an operation calls itself) is always synchronous and is
marked as such in the sequence diagram.
-In this case, we are showing the reply message to explicitly show the returns.
-This reply is often just considered implied by the bottom of the execution
occurrence and is left off.

16-Nov-20 T.A GHADEER AL-HOMYANI 25


Recursion

16-Nov-20 T.A GHADEER AL-HOMYANI 26

You might also like