lecture-09-sequencediagrams
lecture-09-sequencediagrams
Software Engineering
Lecture 9
UML Sequence Diagrams
Reading:
UML Distilled, Ch. 4, M. Fowler
2
Key parts of a Sequence
diag.
• participant: object or entity that acts in the diagram
– diagram starts with an unattached "found message"
arrow
5
Why Sequence Diagrams
• Showing dynamic interactions between objects using
sequence diagrams
• Purpose
– See if our class diagram can satisfy each step of the use
case
• Identify more classes that we may have missed in class
diagram
• Identify methods of those classes
6
Representing objects
• Squares with object type, optionally preceded by
"name :"
– write object's name if it clarifies the diagram
– object's "life line" represented by dashed vert. line
7
Messages between
objects
• messages (method calls) indicated by arrow to other
object
– write message name and arguments above arrow
8
Messages, continued
• messages (method calls) indicated by arrow to other
object
– dashed arrow back indicates return
– different arrowheads for normal / concurrent
(asynchronous) calls
9
Lifetime of objects
• creation: arrow with 'new'
written above it
– notice that an object
created after the start of
the scenario appears lower
than the others
• deletion: an X at bottom of
object's lifeline
– Java doesn't explicitly
delete objects; they fall
out of scope and are
garbage-collected
10
Indicating method calls
• activation: thick box over object's life line; drawn
when 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
Activation
Nesting
11
Example: Use case
• UC1: Comment Document
• Flow of events
– The advisor wants to comment a document
– The advisor clicks the “comment document” link
– The system displays list of documents for comment
– The advisor selects a specific document
– The system displays the “comment document” form
– The advisor fills out the form and clicks submit button.
– The system adds the comment and displays a
confirmation message
– The use case ends
12
Example: Class Diagram
User
-accountId
-firstName
-fathersName
-email
-userName
-userPassword
-type
+authenticate()
+resetPassword()
+updateProfile()
+removeUser()
adds 1
0..*
adds
Project Coordinator adds WebMaster Advisor
Student 1 -Title
-title -title 0..*
-yearLevel 1 -status
+addProjectCoordinator() 0..* 1 +addUser()
-status +addAdvisor()
0..*
+addStudent() +getAdvisorNames()
+getStudentNames() 1 +activateAccount()
1 1
+activateAccount() defines creates +deactivateAccount()
+deactivateAccount()
1
4 1
2..5 1 1
posts
Phase Announcement
posts 0..*
adds -title -announcementId
-startDate -title
-deadLine 0..* -date
-part -type
+addPhase() +getInformation()
+getPhaseInfo() belongs to +getAnnouncementTitles()
+getPhaseTitles() 2 +addAnnouncemnet()
+updatePhase() +updateAnnouncement()
1
+removePhase() +deleteAnnouncment()
Document
belongs to uploads -title 1 uploads
-year
-versionNo
1-1
has -type
-submittedDate
-status
* -filePath 1
0..*
+uploadDocument()
+getDocumentInformation()
+archiveDocument()
ProjectGroup
-0..* +searchArchivedDocument()
-id is comment of
-title
-year * 1..* 1 advises
+assignMembers()
+assignAdvisor()
0..1 +getProjectGroupTitles()
+addProjectGroup()
+deleteProjectGroup()
13
+updateProjectGroup()
Example: Sequence
Comment Document
Diagram
• SEQ1: Comment document for UC1
:Advisor :CommentLink :CommentDocument :Document :DocumentListPage :CommentForm :Confirmation
<<Actor>> <<boundary>> <<controller>> <<entity>> <<boundary>> <<boundary>> <<boundary>>
click()
create()
create()
list of Documents
create()
list of documents
select
selection
create
fillContent()
submit
submitted
check()
create()
created
create()
Diplay confirmation
14
Selection and loops
• frame: box around part of diagram to indicate if or
loop
– if -> (opt) [condition]
– if/else -> (alt) [condition], separated by horizontal
dashed line
– loop -> (loop) [condition or items to loop over]
15
Linking sequence
diagrams
• If one diagram is too large or refers to another, indicate
with:
– an unfinished arrow and comment,
– or a "ref" frame that names the other diagram
Approved?
16
Example sequence
diagram
sd Example
loop
AddItem
ReserveItem
Checkout
ProcessOrder
ConfirmOrder
PlaceItemInOrder
17
Why not just code it?
• Sequence diagrams can be somewhat close to the code
level.
2. Control Objects
Represents an entity or manager that makes decisions (e.g. figures
out what to do when a button is pressed)
In simple systems, this is usually the application itself, and there
is typically only a single Control Object
3. Entity Objects
A data store or persistence element that captures or represents
information (often multiple objects)
19
Boundary, Entity, and Control elements
must obey the following relationships
1. Actors can only talk to
boundary objects.
20
The following relationships are generally
restricted or not permitted
1. Actors can only talk to boundary
objects.
21
Example ReportEmergency use
case
Report Manage
EmergencyButton EmergencyControl
FieldOfficer
press() «create»
ReportEmergency
Control
«create» ReportEmergency
Form
fillContents()
submit()
submitReport
«create»
Emergency
Report
submitReportToDispatcher()
«destroy»
22
Sequence diagram
exercise
• Let's do a sequence diagram for the following casual
use case for a scheduler app, Add Calendar
Appointment :
The scenario begins when the user chooses to add a new
appointment in the UI. The UI notices which part of the calendar is
active and pops up an Add Appointment window for that date and
time.
24