Sequence Diagram

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Sequence Diagram

Eng. Diana Jouhari


UML
Diagram

Behavior Structure
Diagram Diagram

State
Activity Class Component Object
Machine
Diagram Diagram Diagram Diagram Diagram
Composite Deployment Package
Interaction Use Case
structure Diagram Diagram
Diagram Diagram Diagram
Profile
Diagram
Communication Interaction Sequence Timing
Diagram overview Diagram Diagram
Diagram
Sequence Diagram Concept
We use a sequence diagram to illustrate use-case realizations and
show how objects interact to perform the behavior of all or part of a use
case.

A sequence diagram describes a pattern of interaction among objects,


arranged in a chronological order; it shows the objects participating in
the interaction by their "lifelines" and the messages that they send to
each other.

Sequence diagrams are particularly important to designers because


they clarify the roles of objects in a flow and thus provide basic input
for determining class responsibilities and interfaces.
Sequence diagram purpose
We can have objects and actor instances in sequence diagrams,
together with messages describing how they interact.

The diagram describes what takes place in the participating objects, in


terms of activations, and how the objects communicate by sending
messages to one another.
The notation

• An empty UML 2 frame element


Lifelines
• An object is shown as a vertical dashed line called the "lifeline".

• The lifeline represents the existence of the object that participate in the
sequence being modeled at a particular time.

• lifeline notation elements are placed across the top of the diagram

• 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.


Lifeline’s name
Messages
• The first message of a sequence diagram always starts at the top and
is typically located on the left side of the diagram for readability.

• Subsequent messages are then added to the diagram slightly lower

• message is shown as a horizontal solid arrow from the lifeline of one


object to the lifeline of another object.

• To show an object sending a message to another object, solid


arrowhead (if a synchronous call operation) or with a stick arrowhead
(if an asynchronous signal).

• The message/method name is placed above the arrowed line


synchronous message
Asynchronous message
Return messages
• These return messages are optional

• a return message is drawn as a dotted line with an open arrowhead


back to the originating lifeline,

• above this dotted line you place the return value from the operation.
Focus of Control
Focus of Control represents the period during which an element is
performing an operation. The top and the bottom of the of the
rectangle are aligned with the initiation and the completion time
respectively
Messages Ex
Recursive Message
• some time times the object will need to send a message to itself

• To draw an object calling itself, you draw a message as you would


normally, but instead of connecting it to another object, you connect
the message back to the object itself
Creation and Destruction
Messages
Guards [ ]
• When modeling object interactions, there will be times when a
condition must be met for a message to be sent to the object.

• Guards are used throughout UML diagrams to control flow.


Alternatives
Alternatives are used to designate a mutually exclusive choice
between two or more message sequence

(if else )
Option
The option combination fragment is used to model a sequence that,
given a certain condition, will occur; otherwise, the sequence does not
occur.

"if then" statement


Loops
• To model a repetitive sequence
• Draw a frame, and in the frame's name box the text "loop" is placed
• Inside the frame's content area the loop's guard is placed towards the
top left corner, on top of a lifeline
Referencing another sequence
diagram
Reuse existing sequence diagrams in other sequences diagram.
Gates
• Gates can be an easy way to model the passing of information
between a sequence diagram and its context

• A gate is merely a message that is illustrated with one end connected


to the sequence diagram's frame's edge and the other end connected
to a lifeline

• The getBalance message is an entry gate, because it is the arrowed


line that is connected to the diagram's frame with the arrowhead
connected to a lifeline
Parallel
Sequence diagram Vs.
Collaboration diagram
• sequence diagram and collaboration diagram are used as interaction
diagrams and their details about the behavioral aspects of the
system.

• sequence diagram does not describe the object organization, whereas


the collaboration diagram shows the object organization.

• If the time sequence is important, then the sequence diagram is


used. If organization is required, then collaboration diagram is used.
sd Example

StoreFront Cart Inventory

loop
AddItem
ReserveItem

Checkout

ProcessOrder
ConfirmOrder

PlaceItemInOrder

You might also like