0% found this document useful (0 votes)
163 views

UML Sequence Diagrams: CSE 403: Software Engineering, Spring 2015

This document provides an overview of UML sequence diagrams, including: - Sequence diagrams model a single scenario by showing messages sent between objects and when. - Key parts include participants (objects), messages (communication between objects), and time represented by the vertical axis. - Objects are represented by boxes with the object type and name, and messages are shown as labeled arrows between objects. - Activation boxes indicate when an object's method is executing.

Uploaded by

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

UML Sequence Diagrams: CSE 403: Software Engineering, Spring 2015

This document provides an overview of UML sequence diagrams, including: - Sequence diagrams model a single scenario by showing messages sent between objects and when. - Key parts include participants (objects), messages (communication between objects), and time represented by the vertical axis. - Objects are represented by boxes with the object type and name, and messages are shown as labeled arrows between objects. - Activation boxes indicate when an object's method is executing.

Uploaded by

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

CSE 403: Software Engineering, Spring 2015

courses.cs.washington.edu/courses/cse403/15sp/

UML Sequence Diagrams

Emina Torlak
[email protected]
Outline

• Overview of sequence diagrams


• Syntax and semantics
• Examples

2
intro
an overview of sequence diagrams
What is a UML sequence diagram?

4
What is a UML sequence diagram?

• Sequence diagram: an “interaction diagram” that


models a single scenario executing in a system
• 2nd most used UML diagram (behind class diagram)
• Shows what messages are sent and when

4
What is a UML sequence diagram?

• Sequence diagram: an “interaction diagram” that


models a single scenario executing in a system
• 2nd most used UML diagram (behind class diagram)
• Shows what messages are sent and when

• Relating UML diagrams to other design artifacts:


• CRC cards → class diagrams
• Use cases → sequence diagrams

4
Key parts of a sequence diagram

:Client :Server

checkEmail
sendUnsentEmail

newEmail
response
[newEmail] get

deleteOldEmail

5
Key parts of a sequence diagram

• Participant: an object or an entity;


:Client :Server
the sequence diagram actor
• sequence diagram starts with an checkEmail
unattached "found message" arrow sendUnsentEmail

newEmail
response
[newEmail] get

deleteOldEmail

5
Key parts of a sequence diagram

• Participant: an object or an entity;


:Client :Server
the sequence diagram actor
• sequence diagram starts with an checkEmail
unattached "found message" arrow sendUnsentEmail

• Message: communication between


newEmail
objects
response
[newEmail] get

deleteOldEmail

5
Key parts of a sequence diagram

• Participant: an object or an entity;


:Client :Server
the sequence diagram actor
• sequence diagram starts with an checkEmail
unattached "found message" arrow sendUnsentEmail

• Message: communication between


newEmail
objects
response
• Axes in a sequence diagram: [newEmail] get
• horizontal: which participant is acting
deleteOldEmail
• vertical: time (↓ forward in time)

5
Key parts of a sequence diagram

• Participant: an object or an entity;


:Client :Server
the sequence diagram actor
• sequence diagram starts with an checkEmail
unattached "found message" arrow sendUnsentEmail

• Message: communication between


newEmail
objects
response
• Axes in a sequence diagram: [newEmail] get
• horizontal: which participant is acting
deleteOldEmail
• vertical: time (↓ forward in time)

5
Sequence diagram from a use case

1. The user presses the “check email”


:Client :Server
button.
2. The client first sends all unsent email checkEmail
sendUnsentEmail
to the server.
3. After receiving an acknowledgement, newEmail
the client asks the server if there is response
any new email. [newEmail] getEmail

4. If so, it downloads the new email.


deleteOldEmail
5. Next, it deletes old thrashed email
from the server.

6
basics
sequence diagrams: syntax and semantics
Representing objects

objectname:classname

Named object Anonymous object

Smith:Patient :Patient Smith

Object of unknown class

8
Representing objects

objectname:classname

• An object: a box with an underlined Named object Anonymous object


label that specifies the object type,
and optionally the object name.
Smith:Patient :Patient Smith
• Write the object's name if it clarifies
the diagram.
Object of unknown class

8
Representing objects

objectname:classname

• An object: a box with an underlined Named object Anonymous object


label that specifies the object type,
and optionally the object name.
Smith:Patient :Patient Smith
• Write the object's name if it clarifies
the diagram.
• An object's "life line" is represented Object of unknown class
by a dashed vertical line.
• Represents the life span of the object Lifeline
during the scenario being modeled.

8
Representing messages between objects

• A message (method call): horizontal :Hospital


arrow to the receiving object.
• Write message name and arguments admit(patientID, roomType)
above the arrow.

9
Different types of messages

:Controller
• Type of arrow indicates types of messages:
• Synchronous message: solid arrow with a solid head.
• Asynchronous message: solid arrow with a stick head.
• Return message: dashed arrow with stick head.

10
Indicating method execution

:Controller
• Activation: thick box over object's life line, drawn
when an object's method is on the stack
• Either that object is running its code,

or it is on the stack waiting for another object's
method to finish
• Nest activations to indicate an object calling itself.
:Controller

11
Lifetime of objects

• Object creation: an arrow with new :Handler


written above it
queryDB
• An object created after the start of the new
scenario appears lower than the others. :Query

• Object deletion: X at the bottom of execute


object's lifeline results
• Java doesn't explicitly delete objects; they
fall out of scope and are garbage collected.

12
Alternatives, options, and loops

• Frame: a box around part of a sequence diagram


• if → (opt) [condition]
• if/else → (alt) [condition], separated by horizontal dashed line
• loop → (loop) [condition or items to loop over]

:Order careful:Distributor regular:Distributor


dispatch

loop [for each line item]

alt [value>1000] dispatch

[else] dispatch

13
Linking sequence diagrams

• If one sequence diagram is too large or refers to another diagram:


• An unfinished arrow and comment.
• A ref frame that names the other diagram.

The flow is
customerInfo
ref
parse continued in
Diagram 2.
Verify Customer Credit
approved

14
Example sequence diagram

:StoreFront :Cart :Inventory

loop
AddItem
ReserveItem

Checkout

ProcessOrder
ConfirmOrder

PlaceItemInOrder

15
Forms of system control

What can you say about the


control flow of each of these
systems?
• Is it centralized?
• Is it distributed?

16
Why use sequence diagrams? Why not code it?

17
Why use sequence diagrams? Why not code it?

• A good sequence diagram is still above the level of the


real code (not all code is drawn on diagram)

17
Why use sequence diagrams? Why not code it?

• A good sequence diagram is still above the level of the


real code (not all code is drawn on diagram)
• Sequence diagrams are language-agnostic (can be
implemented in many different languages)

17
Why use sequence diagrams? Why not code it?

• A good sequence diagram is still above the level of the


real code (not all code is drawn on diagram)
• Sequence diagrams are language-agnostic (can be
implemented in many different languages)
• Non-coders can read and write sequence diagrams.

17
Why use sequence diagrams? Why not code it?

• A good sequence diagram is still above the level of the


real code (not all code is drawn on diagram)
• Sequence diagrams are language-agnostic (can be
implemented in many different languages)
• Non-coders can read and write sequence diagrams.
• Easier to do sequence diagrams as a team.

17
Why use sequence diagrams? Why not code it?

• A good sequence diagram is still above the level of the


real code (not all code is drawn on diagram)
• Sequence diagrams are language-agnostic (can be
implemented in many different languages)
• Non-coders can read and write sequence diagrams.
• Easier to do sequence diagrams as a team.
• Can see many objects/classes at a time on same page
(visual bandwidth).

17
study
sequence diagrams: examples
Flawed sequence diagram 1

:Dialler :CellularRadio

connect(pno)
new
:Connection

connect(pno) What’s wrong with


this sequence
connectionEstablished() diagram?
end()
disconnect()

disconnected()

close()

19
Flawed sequence diagram 2

What’s wrong with


this sequence
diagram?

20
Online bookstore example

1. The customer begins the interaction by searching for a book by title.


2. The system will return all books with that title.
3. The customer can look at the book description.
4. The customer can place a book in the shopping cart.
5. The customer can repeat the interaction as many times as desired.
6. The customer can purchase the items in the cart by checking out.

21
Online bookstore sequence diagram

22
Summary

• A sequence diagram models a single


scenario executing in the system.
• Key components include participants
and messages.
• Sequence diagrams provide a high-
level view of control flow patterns
through the system.

23

You might also like