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

Lecture - Sequence Diagram

Uploaded by

iamnah97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lecture - Sequence Diagram

Uploaded by

iamnah97
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

CSC291 –Software Engineering

Concepts
(Spring 2024)

Sequence Diagrams
06/11/2024 2

Interaction Models

All systems involve the interaction of some kind…

• This can be user interaction, which involves user inputs and outputs.
• Interaction between the system being developed and other systems
• Or interaction between the components of the system.

Use case modeling, which is mostly used to model interactions


between a system and external actors (users or other systems).

Sequence diagrams are used to model interactions between system


components, although external agents may also be included.
06/11/2024 3

Sequence Diagrams
• A sequence diagram shows the sequence of messages exchanged
by the set of objects (and optionally an actor) performing a certain
task.

• The objects are arranged from left to right across the diagram – an
actor that initiates the interaction is often shown on the left.

• The vertical dimension represents time.

• The top of the diagram is the starting point, and time progresses
downwards towards the bottom of the diagram.
06/11/2024 4

Sequence Diagram Key Parts


In a sequence diagram, objects and actors are aligned
along the top of the diagram.

Object1 name:classname Object 2name:classname

Actors
Objects
06/11/2024 5

Sequence Diagram Key Parts


• Labeled arrows indicate operations; the sequence of
operations is from top to bottom.

• The axes in a sequence diagram:

– horizontal: Represents that which object/participant is acting


– vertical: Represents time sequence
06/11/2024 6

Sequence Diagram Notation


Object1 Object 2

Lifelines
A vertical dashed line, called a lifeline, is attached to each object
or actor.
06/11/2024 7

Sequence Diagram Notation


Object 1 Object 2

Activations
The lifeline becomes a box, called an activation box, during
the period of time that the object is performing computations.
06/11/2024 8

Sequence Diagram Notation


Object 1 Object 2

message

Messages
A message is represented as an arrow between activation boxes of
the sender and receiver. You give each message a label.
06/11/2024 9

Sequence Diagram Notation


Object 1 Object 2

message

message

Sequence
Vertical position signifies sequence – earlier
messages appear nearer the top.
06/11/2024 10

Developing Sequence Diagrams


There are four main steps to draw sequence diagram:

• Identify the relevant objects involved in the computation

• Establish the role of each object

• Identify the controller

• Decide messages between objects


06/11/2024 11

Sequence Diagram (make a phone call)


06/11/2024 12

A Simple Example - Sending an email


06/11/2024 13

E-mail Interface
06/11/2024 14

Working From a Scenario


Sending an email

1. Press “New ” email icon


2. Enter the person’s name in the “To” section
3. Type subject
4. Type contents
5. Press the Send button
6. The system looks up email addresses in the address book
7. System submits the email to the email server
06/11/2024 15

Starting The Diagram


• If this is an interactive scenario, we always have an actor
driving it

: user
06/11/2024 16

Add Objects
The first interaction is with the icon bar, which we can treat as an
object
: icon bar

: user
06/11/2024 17

Add Message
The user talks to the icon bar

: icon bar

: user
06/11/2024 18

Label The Communication


: icon bar

: user
click send mail

Remember that actors can only communicate with interface


objects such as screens, menus and icon bars.
06/11/2024 19

The icon bar has some work to do.


It creates an email page.

: icon bar : email page

: user
click send mail create

Now the user can see the email page and use it.
06/11/2024 20

The next three steps are filling in the details on


the email page

: icon bar : email page

: user
click send mail create

fill in to box
fill in subject box
fill in contents box
06/11/2024 21

The User then clicks Send


: icon bar : email page

: user
click send mail create

fill in to box
fill in subject box
fill in contents box

send
06/11/2024 22

Now consider how to do the sending


: icon bar : email page : address book

: user
click send mail create

fill in to box
fill in subject box
fill in contents box

send
look up email address

We can choose to get the email page to look up the email


address from an address book object
06/11/2024 23

The arrow allows information to return


: icon bar : email page : address book

: user
click send mail create

fill in to box
fill in subject box
fill in contents box

send
look up email address

So we don’t need to put a return arrow with the email


address going back to the email page
06/11/2024 24

We can choose to get the email page to submit the email


to the email server

: icon bar : email page : address book : email server

: user
click send mail create

fill in to box
fill in subject box
fill in contents box

send
look up email address

submit email
06/11/2024 25

And if we think carefully, the email page always closes after


the send.
: icon bar : email page : address book : email server

: user
click send mail create

fill in to box
fill in subject box
fill in contents box

send
look up email address

submit email

close
06/11/2024 26

Now we go through and change the messages to


operations on the object

: icon bar : email page : address book : email server

: user
send mail( ) create

fill in to box
fill in subject box
fill in contents box

send
look up email address

submit email

close
06/11/2024 27

And so on, all the way through

: icon bar : email page : address book : email server

: user
send mail( ) create( )

enterTo( )
enterSubject( )
enterContents( )

send( )
getEmailAddress( )

submitEmail( )

close( )
06/11/2024 28

And now we have found our objects, and the operations on


them

email page

create()
icon bar enterTo() address book
enterSubject()
send mail() enterContents() getEmailAddress()
send()
close()

email server

submitEmail()

So we drag them onto a class diagram


06/11/2024 29

Exercise
Consider the following scenario and draw sequence diagram for
online book shop.

“Online customer can search book catalog, view description of


a selected book, add book to shopping cart, do checkout”.
06/11/2024 30

Sequence Fragment

• A sequence fragment is represented as a box that frames a


section of interactions between objects in a sequence diagram.

• It is used to show complex interactions such as alternative


flows and loops in a more structured way.

• On the top left corner of the fragment sits an operator.


This – the fragment operator – specifies what sort of a
fragment it is.
06/11/2024 31

Alternative Fragment
• The alternative fragment is used when a choice needs to be
made between two or more message sequences. It models
the “if then else” logic.

• The alternative fragment is represented by a large rectangle


or a frame; it is specified by mentioning ‘alt’ inside the
frame’s name box

• To show two or more alternatives, the larger rectangle is


then divided using a dashed line
06/11/2024 32

An alternative fragment provides several guarded alternative fragments


06/11/2024 33

Option Fragment
• The option fragment is used to indicate a sequence that will
only occur under a certain condition, otherwise, the
sequence won’t occur. It models the “if-then” statement.

• Similar to the alternative fragment, the option fragment is


also represented with a rectangular frame where ‘opt’ is
placed inside the name box.

• Unlike the alternative fragment, an option fragment is not


divided into two or more operands. The option’s guard is
placed at the top left corner.
06/11/2024 34

An optional fragment is only executed if some guard condition is


true
06/11/2024 35

Exercise
Draw a sequence diagram that represents the process of exam conduction
described in the case study below:
Before the exam conduction, the instructor first informs the students of the exam
date and the syllabus (material) included as part of exam. The instructor then
prepares the exam paper. The instructor then gets the exam paper copied from
staff to produce enough copies for the students, and later the instructor hands
over the exam paper to the students on the designated time and location.
The students are required to write their answers against questions listed in the
exam paper. Students should hand in their solution sheet to the instructor before
time runs out.
The instructor then gives the solution sheet of students to the Teaching
Assistance (TAs), along with sample solutions to each question, and gets them to
mark it. TAs then return solution Sheet to instructor after marking. She then
records all marks and inform result to the students.
06/11/2024 36

Home Task (Reading Assignment)

• Loop Fragment
• Reference fragment
06/11/2024 37

Chapter Reading
• Chapter 5, System Modeling,
Software Engineering by Ian Sommerville

You might also like