You are on page 1of 50

SEQUENCE DİAGRAMS

EXAMPLE
 Draw a UML Class Diagram representing the following elements from the problem domain for a hockey
league.

 A hockey league is made up of at least four hockey teams.


 Each hockey team is composed of six to twelve players, and one player captains the team.
 A team has a name and a record.
 Players have a number and a position.
 Hockey teams play games against each other.
 Each game has a score and a location.
 Teams are sometimes lead by a coach.
 A coach has a level of accreditation and a number of years of experience, and can coach multiple teams.
 Coaches and players are people, and people have names and addresses.

 Draw a class diagram for this information, and be sure to label all associations with appropriate
multiplicities.
SOLUTION
 A hockey league is made up of at least four
hockey teams.
 Each hockey team is composed of six to twelve
players, and one player captains the team.
 A team has a name and a record.
 Players have a number and a position.
 Hockey teams play games against each other.
 Each game has a score and a location.
 Teams are sometimes lead by a coach.
 A coach has a level of accreditation and a
number of years of experience, and can coach
multiple teams.
 Coaches and players are people, and people
have names and addresses.
SEQUENCE DİAGRAM

 From the flow of events in the use case or scenario proceed to the sequence
diagram
 A sequence diagram is a graphical description of the objects participating in
a use case using a DAG (directed acyclic graph) notation
 Relation to object identification:
 Objects/classes have already been identified during object modeling
 Objects are identified as a result of dynamic modeling
 Heuristic for finding participating objects:
 A event always has a sender and a receiver
 The representation of the event is sometimes called a message
 Find them for each event => These are the objects participating in the use case.
LİFELİNES

Object1
Underline on name
indicates object (vs class)
Represents time during
which the object exists.

May run entire length of


diagram or may start or end
within the diagram
MESSAGES

 Interactions are represented by messages sent from one object to another.


 Long narrow vertical box on lifeline indicates focus of control.
 When an object is active, either because it is doing something, or because it has
sent a message to another object that is doing something on its behalf.
 Not always shown.
MESSAGES

Arrows are labeled with the name of the message, or


stimulus, that they represent.
TYPES OF MESSAGES

UML defines four types of messages:


Sender waits for a reply
Synchronous (Procedural message)

Return
The reply to a synchronous
message Often not shown

Asynchronous Sender does not wait for a reply

Flat
Don’t know or don’t care
SYNCHRONOUS MESSAGES

 A synchronous message is represented by


an arrow with a continuous line and a
filled triangular arrowhead.
 In the case of synchronous messages, the
sender waits until it has received a
response message before continuing.
 The response (return) message is
represented by a dashed line with an open
arrowhead.
ASYNCHRONOUS MESSAGE

 Used when we don’t want the sender to wait for a response


 Typically a one way message
 No response is sent.
FLAT MESSAGES

 Used when we don’t want to specify whether or not sender waits for a reponse.
 Haven’t decided yet.
 Isn’t important
 Specifically want to leave as an implementation decision.
MESSAGES
 Messages are identified by a name, with the optional specification of parameters and a
return value.

 The parameters are separated by commas and are enclosed within parentheses.
 The return value can optionally be assigned to a variable as well.
 Thus, a message can be labeled with var=m1:value, whereby var is the variable to
which the return value is to be assigned, m1 specifies the name of the message, and
value represents the actual return value.
SEQUENCE DİAGRAM
SEQUENCE DİAGRAM
Time Increasing -->

All lines should be horizontal to indicate instantaneous actions.


Additionally if ActivityA happens before ActivityB, ActivityA must
be above activity A

Lower = Later!
COMPONENTS

Objects: aStudent is a specific


instance of the Student class

Generic
Generic (unnamed)
(unnamed)
Specific
Instance of an objects ofobjects
class type Seminar
Object and Course
COMPONENTS

execution
lifeline
COMPONENTS

Method call

Return value
A SİMPLER EXAMPLE - SENDİNG AN EMAİL
WORKİNG FROM A SCENARİO

Sending an email

1. Press “New ” email icon


2. Enter person’s name in “To” section
3. Type subject
4. Type contents
5. Press Send button
6. System looks up email address in address book
7. System submits the email to the email server
STARTİNG THE DİAGRAM

 If this is an interactive scenario, we always have an actor driving it, so we put one on
the sequence diagram

: user
ADD OBJECTS

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

: icon bar

: user
ADD MESSAGE

The user talks to the icon bar

: icon bar

: user
LABEL THE COMMUNİCATİON

: icon bar

: user
click send mail

Remember that actors can only communicate with interface objects such as screens,
menus and icon bars.
THE İCON 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.
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
THE USER THEN CLİCKS SEND

: icon bar : email page

: user
click send mail create

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

send
NOW CONSİDER HOW TO DO THE SENDİNG

: 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
THE ARROW ALLOWS İNFORMATİON 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
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
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
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
And so on, all the way through

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

: user : user
click send mail create send mail( ) create( )

fill in to box enterTo( )


fill in subject box enterSubject( )
fill in contents box enterContents( )

send send( )
look up email address getEmailAddress( )

submit email submitEmail( )

close close( )
USİNG SCENARİOS

 Stories illustrated by sequence diagrams

Payday

ibm:Employer lourdes:Bank jo:Employee


IBM transfers money pay
to Jo's account at her Bank

IBM notifies Jo that she payslip


has been paid

Jo can now collect cash get cash


from her Bank.
SCENARİO WİTH SEQUENCE DİAGRAM

Interactions between actors: This is a form of instance diagram: it just shows one example of
what could occur
Sequence diagram
use-case check in jo : Person chris: Receptionist rms: Room Manager System
Person arrives at desk, arrive
gives name.
get room map
R gets map of available choose room
Rooms, chooses one.
get details
R enters Person’s details person details

time
on Room Management
system against chosen confirm room assignment
room.
R gives key to Person. key

Used to work out use-case implementation at high level


 No internal details of system
EXAMPLE

Use case diagram example of ‘Create New Online


Library Account’, we will focus on the use case named
‘Create New User Account’ to draw our sequence
diagram example.

Before drawing the sequence diagram, it’s necessary to


identify the objects or actors that would be involved in
creating a new user account. These would be;

•Librarian
•Online Library Management system
•User credentials database
•Email system
EXAMPLE

Here are the steps that occur in the use case


named ‘Create New Library User Account’.

•The librarian request the system to create a new


online library account
•The librarian then selects the library user
account type
•The librarian enters the user’s details
•The user’s details are checked using the user
Credentials Database
•The new library user account is created
•A summary of the of the new account’s details
are then emailed to the user
The librarian request the system to create a new online library account
The librarian then selects the library user account type
The librarian enters the user’s details
The user’s details are checked using the user Credentials Database
The new library user account is created
A summary of the of the new account’s details are then emailed to the user
EXAMPLE
EXAMPLE
EXAMPLE
EXAMPLE

 Consider the following simplified sequence diagram for an


online shopping system.
EXAMPLE
EXAMPLE

 Create a sequence diagram for each of the following scenario descriptions


for a health club membership system:

 Every time a member enters the club, an attendant takes his or her card and
scans it to make sure that the person is an active member. If the member is
not active, the system presents the amount of money it costs to renew the
membership. The customer is given the chance to pay the fee and use the
club, and the system makes note of the reactivation of the account so that
special attention can be given to this customer when the next round of
renewal notices is dispensed.
EXAMPLE
EXAMPLE (CONT.)
EXAMPLE
REFERENCES

 Object-Oriented Software Engineering Using UML, Patterns, and Java, by


Bernd Bruegge and Allen H. Dutoit
 Systems Analysis and Design: An Object-Oriented Approach with UML, by
Alan Dennis, Barbara Haley Wixom, David Tegarden
 UML @ Classroom, An Introduction to Object-Oriented Modeling. Martina
Seidl, Marion Scholz, Christian Huemer, Gerti Kappel
 Course materials of Dr. Dan Fleck
 http://ziedzaier.com/wp-content/uploads/2015/05/Sequence-Diagrams.ppt

You might also like