You are on page 1of 42

4.

Sequence Diagram
Collaboration Diagram
Objects

• Process View – Interaction Diagram


 Sequence Diagram
 Collaboration Diagram (Communication Diagram)

Analysis and Design of IS 2


Purpose

• Observe the dynamic behavior of a system.


• Visualizes the communication and sequence of
message passing in the system.
• Represents the structural aspects of various
objects in the system.
• Represents the ordered sequence of interactions
within a system.
• Provides the means of visualizing the real time
data via UML.
• Can be used to explain the architecture of an
object-oriented or a distributed system.

Analysis and Design of IS 3


Types of Interaction diagrams

There are two types of interaction diagrams:


• Sequence diagrams:
 emphasize the order / Sequence or
concurrency of the interactions.
• Collaboration diagrams:
 emphasize the interacting objects.

Analysis and Design of IS 4


Sequence diagrams Collaboration diagrams

Analysis and Design of IS 5


Sequence Diagram

• Object

Analysis and Design of IS 6


• As with any UML-element, we can add a
stereotype to a target. Some often used
stereotypes for objects are «actor»,
«boundary», «control», «entity».

Analysis and Design of IS 7


• an actor element symbol is used when the
particular sequence diagram is owned by a
use case.

• a boundary element indicates a system


boundary/ software element in a system; for
example, user interface screens, database
gateways or menus that users interact
with, are boundaries.

Analysis and Design of IS 8


• a control element indicates a controlling
entity or manager. It organizes and
schedules the interactions between the
boundaries and entities and serves as the
mediator between them.

• an entity element represents system data.


For example, in a customer service
application, the Customer entity would
manage all data related to a customer.

Analysis and Design of IS 9


Terminology

Lifeline
• A lifeline represents a single participant in an interaction.
It describes how an instance of a specific classifier
participates in the interaction.
• A lifeline represents a role that an instance of the
classifier may play in the interaction. Following are
various attributes of a lifeline,
• Name
 It is used to refer the lifeline within a specific interaction.
 A name of a lifeline is optional.
• Type
 It is the name of a classifier of which the lifeline represents an
instance.
• Selector
 It is a Boolean condition which is used to select a particular
instance that satisfies the requirement.
 Selector attribute is also optional.
Analysis and Design of IS 10
Types of Messages

• Synchronous Message
 A synchronous message requires a response
before the interaction can continue. It's usually
drawn using a line with a solid arrowhead pointing
from one object to another.

Analysis and Design of IS 11


• Synchronous Message (2)
 If you want to show that the receiver has finished processing
the message and returns control to the sender, draw a
dashed arrow from receiver to sender. Optionally, a value
that the receiver returns to the sender can be placed near
the return arrow.

 If you want your diagrams to be easy to read, only show the


return arrow if a value is returned. Otherwise, hide it.

Analysis and Design of IS 12


• Example

Analysis and Design of IS 13


Types of Messages

• Asynchronous Message
 Asynchronous messages don't need a reply for
interaction to continue. Like synchronous
messages, they are drawn with an arrow
connecting two lifelines; however, the arrowhead
is usually open and there's no return message
depicted.

Analysis and Design of IS 14


• Example (normal):

Analysis and Design of IS 15


• Reply or Return Message
 A reply message is drawn with a dotted
line and an open arrowhead pointing back
to the original lifeline.
• Self Message
 A message an object sends to itself,
usually shown as a U shaped arrow
pointing back to itself.

Analysis and Design of IS 16


• Create Message
 This is a message that creates a new object.
Similar to a return message, it's depicted with a
dashed line and an open arrowhead that points to
the rectangle representing the object created.

Analysis and Design of IS 17


• Delete Message
 This is a message that destroys an object. It can be
shown by an arrow with an x at the end.

Analysis and Design of IS 18


• Found Message
 A message sent from an unknown recipient, shown
by an arrow from an endpoint to a lifeline.
• Lost Message
 A message sent to an unknown recipient. It's
shown by an arrow going from a lifeline to an
endpoint, a filled circle or an x

Analysis and Design of IS 19


• Lifeline Start and End
 A lifeline may be created or destroyed during the timescale
represented by a sequence diagram. In the latter case, the lifeline
is terminated by a stop symbol, represented as a cross. In the
former case, the symbol at the head of the lifeline is shown at a
lower level down the page than the symbol of the object that
caused the creation. The following diagram shows an object being
created and destroyed.

Analysis and Design of IS 20


• Duration and Time Constraints
 By default, a message is shown as a horizontal
line. Since the lifeline represents the passage of
time down the screen, when modelling a real-time
system, or even a time-bound business process, it
can be important to consider the length of time it
takes to perform actions.
By setting a duration constraint
for a message, the message
will be shown as a sloping line.

Analysis and Design of IS 21


• Operator
 An operator specifies an operation on how the
operands are going to be executed.
Operator Name Meaning
Opt Option An operand is executed if the condition is true.
e.g., If else
Alt Alternative The operand, whose condition is true, is
executed. e.g., switch
Loop Loop It is used to loop an instruction for a specified
period.
Break Break It breaks the loop if a condition is true or false,
and the next instruction is executed.
Ref Reference It is used to refer to another interaction.
Par and Design
Analysis Parallel
of IS All operands are executed in parallel. 22
• opt - if

Analysis and Design of IS 23


• Example: opt - if

Analysis and Design of IS 24


• alt – switch

Analysis and Design of IS 25


Analysis and Design of IS 26
• Example: loop

Analysis and Design of IS 27


• Example – loop-break

Analysis and Design of IS 28


• Example

Analysis and Design of IS 29


• Sequence diagram for issuing book

Analysis and Design of IS 30


• Sequence diagram for returning book

Analysis and Design of IS 31


Analysis and Design of IS 32
Collaboration Diagram

• Depicts the relationships and interactions


among software objects. They are used to
understand the object architecture within a
system rather than the flow of a message as
in a sequence diagram. They are also known
as “Communication Diagrams.”

Analysis and Design of IS 33


Analysis and Design of IS 34
• Benefits
 It is also called as a communication diagram.
 It emphasizes the structural aspects of an
interaction diagram - how lifeline connects.
 Its syntax is similar to that of sequence diagram
except that lifeline don't have tails.
 Messages passed over sequencing is indicated
by numbering each message hierarchically.

Analysis and Design of IS 35


• Benefits (2)
 Compared to the sequence diagram communication
diagram is semantically weak.
 Object diagrams are special case of communication
diagram.
 It allows you to focus on the elements rather than
focusing on the message flow as described in the
sequence diagram.
 Sequence diagrams can be easily converted into a
collaboration diagram as collaboration diagrams are
not very expressive.
 While modeling collaboration diagrams w.r.t sequence
diagrams, some information may be lost.

Analysis and Design of IS 36


• Drawbacks of a Collaboration Diagram
 Collaboration diagrams can become complex
when too many objects are present within the
system.
 It is hard to explore each object inside the system.
 Collaboration diagrams are time consuming.
 The object is destroyed after the termination of a
program.
 The state of an object changes momentarily,
which makes it difficult to keep track of every
single change the occurs within an object of a
system.

Analysis and Design of IS 37


• Example

Analysis and Design of IS 38


• Example - Printing

Analysis and Design of IS 39


• Example – Printing [wait]

Analysis and Design of IS 40


Exercise

• Sequence Diagram:

Analysis and Design of IS 41


Analysis and Design of IS 42

You might also like