0% found this document useful (0 votes)
44 views24 pages

lecture-09-sequencediagrams

Uploaded by

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

lecture-09-sequencediagrams

Uploaded by

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

ITSE 2F12

Software Engineering
Lecture 9
UML Sequence Diagrams

Reading:
UML Distilled, Ch. 4, M. Fowler

slides adopted from Marty Stepp at


http://www.cs.washington.edu/403/
UML sequence diagrams
• sequence diagram: an "interaction diagram" that
models a single use case executing in the system
– Shows what messages (method calls) are sent between
objects and when
• Class diagrams were static, sequence diagrams are dynamic
– perhaps 2nd most used UML diagram (behind class
diagram)

• relation of UML diagrams to other exercises:


– CRC cards  class diagram
– use cases  sequence diagrams

2
Key parts of a Sequence
diag.
• participant: object or entity that acts in the diagram
– diagram starts with an unattached "found message"
arrow

• message: communication between


participant objects

• the axes in a sequence diagram:


– Horizontal: which object/participant
is acting
– Vertical: time (down = forward
in time)
3
Key parts of a Sequence
diag.
• participant: object or entity that acts in the diagram
– diagram starts with an unattached "found message"
arrow

• message: communication between


participant objects

• the axes in a sequence diagram:


– Horizontal: which object/participant
is acting
– Vertical: time (down = forward
in time)
4
Sequence diagram from a use
case
• The user presses the “check
email”.
• The client first sends all unsent
email to the server.
• After receiving an
acknowledgement, the client
asks the server if there is any
new email.
• If so, it downloads the new
email.
• Next, it deletes old thrashed
email from the server.

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

Customer Info ref

Verify customer credit

Approved?

16
Example sequence
diagram
sd Example

StoreFront Cart Inventory

loop
AddItem
ReserveItem

Checkout

ProcessOrder
ConfirmOrder

PlaceItemInOrder

17
Why not just code it?
• Sequence diagrams can be somewhat close to the code
level.

• So why not just code up that algorithm rather than


drawing it as a sequence diagram?
– a good sequence diagram is still a bit 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 do sequence diagrams
– easier to do sequence diagrams as a team
– can see many objects/classes at a time on same page
(visual bandwidth)
18
Recap: Three different Types
of objects
1. Boundary Objects
Model the system boundary (often multiple)
User Interface elements (entire screens,
but not individual ui elements)

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.

2. Boundary objects can


usually only talk to
controllers and actors.

3. Entity objects can usually


only talk to controllers and
boundary objects.

4. Controllers can talk to


boundary objects and entity
objects, and to other
controllers, but not to actors

20
The following relationships are generally
restricted or not permitted
1. Actors can only talk to boundary
objects.

2. Entity objects can communicate


Allowed with with an another Entity that it
reservations
“owns” (e.g. an Collection owns
Allowed with reservations Items in the Collection)
Allowed with
reservations
3. Boundary objects can talk to
certain Entity objects (UI gets
Items from a Collection to display),
and other Boundary objects it
“owns” (e.g. a popup dialog).

4. Controllers can talk to boundary


objects and entity objects, and to
other controllers, but not to actors

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.

The user enters information about the appointment's name,


location, start and end times. The UI will prevent the user from
entering an appointment that has invalid information, such as an
empty name or negative duration. The calendar records the new
appointment in the user's list of appointments. Any reminder selected
by the user is added to the list of reminders.

If the user already has an appointment at that time, the user


is shown a message and asked to choose an available time or replace
the appointment. If the user enters an appointment with the same 23
MVC is not a MUST

24

You might also like