8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 1/46
Slide 1
Use Case
Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 2/46
Slide 2
Interaction Diagrams
Sequence diagrams• generally show the sequence of events that occur .
Collaboration diagramsdemonstrate how objects are statically connected.
Both diagrams are relatively simleto draw and contain similar elements.
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 3/46
Slide 3
Interaction Diagrams
Interaction diagrams model the behavior of usecases by describing the way grous of objectsinteract to comlete the tas! of the use case. "heyortray the interaction among the objects of asystem and describe the dynamic behavior of thesystem.
"here are two tyes of interaction diagrams Sequence Diagrams and Communication
Diagrams #formally !nown as collaborationdiagrams$
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 4/46
Slide 4
Interaction Diagrams
%urose of interaction diagrams
• &odel interactions between objects
• 'ssist in understanding how a system#i.e.( a use case$ actually wor!s
• )erify that a use case descrition can
be suorted by the e*isting classes• Identify resonsibilities+oerations and
assign them to classes
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 5/46
Slide 5
Sequence Diagram
Illustrates the objects that articiate
in a use case and the messages that
ass between them over time for one
use case
In design( used to distribute use case
behavior to classes
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 6/46
Slide 6
Sequence Diagram
member:
LibraryMember book:Book
:Book
Copy
borrow(book)
ok = mayBorrow()
[ok] borrow(member) setTaken(member)
X-Axis (objets)
!-Axi s
( t i m e )
"bjetLi#e
LineMessa$e
%o&s o#
ontro'
Conition
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 7/46 Slide 7
Sequence Diagram Synta*
AN ACTOR
AN OBJECT
A LIFELINE
A FOCUS OF CONTROL
A MESSAGE
OBJECT DESTRUCTION
anObject:aClass
aMessage()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 8/46 Slide 8
Sequence Diagram
"wo major comonents
• 'ctive objects
•Communications between these activeobjects• &essages sent between the active objects
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 9/46 Slide 9
Sequence Diagram
'ctive objects
• 'ny objects that lay a role in the
system• %articiate by sending and+or receiving
messages
• %laced across the to of the diagram• Can be,
• 'n actor #from the use case diagram$
• -bject+class #from the class diagram$ within the
system
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 10/46 Slide 10
'ctive -bjects
-bject• Can be any object or class that is
valid within the system
• -bject naming• Synta*
[instanceName][:className]
. Class name only ,Classname/. Instance name only object0ame
1. Instance name and class nametogether object,Class
myBirty
:*ate
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 11/46 Slide 11
'ctive -bjects
'ctor
• ' erson or system that derives
benefit from and is e*ternal to the
system
• %articiates in a sequence by sending
and+or receiving messages
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 12/46 Slide 12
Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 13/46 Slide 13
Communications
between 'ctive -bjects
&essages
• Used to illustrate communication
between different active objects of asequence diagram
• Used when an object needs
• to activate a rocess of a different object• to give information to another object
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 14/46 Slide 14
&essages
' message is reresented by an arrowbetween the life lines of two objects.
• Self calls are allowed
' message is labeled at minimum with
the message name.
• 'rguments and control information#conditions( iteration$ may be included.
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 15/46 Slide 15
"yes of &essages
Synchronous #flow interrut until the message
has comleted$
'synchronous #don2t wait for resonse$
3lat #no distinction between sysn+async$
4eturn #control flow has returned to the caller$
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 16/46
Slide 16
Synchronous &essages
"he routine that handles the
message is comleted before the
calling routine resumes e*ecution.
:A :B
doYouUnderstand()
Ca''er
B'oke
ret&rn
(optiona')yes
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 17/46
Slide 17
'synchronous &essages
Calling routine does not wait for themessage to be handled before it
continues to e*ecute.
's if the call returns immediately
5*amles
0otification of somebody or something &essages that ost rogress
information
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 18/46
Slide 18
4eturn )alues
-tionally indicated using a dashed arrowwith a label indicating the return value. Don2t model a return value when it is obvious
what is being returned( e.g. get"otal#$ &odel a return value only when you need to
refer to it elsewhere #e.g. as a arameterassed in another message$
%refer modeling return values as art of amethod invocation( e.g. ok = isValid()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 19/46
Slide 19
Sequence Diagram
member:
LibraryMember book:Book
:Book
Copy
borrow(book)
ok = mayBorrow()
[ok] borrow(member) setTaken(member)
X-Axis (objets)
!-Axi s
( t i m e )
"bjetLi#e
LineMessa$e
%o&s o#
ontro'
Conition
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 20/46
Slide 20
-ther 5lements
of Sequence Diagram
6ifeline
3ocus of control #activation bo* ore*ecution occurrence$
Control information
Condition( reetition
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 21/46
Slide 21
Sequence Diagram
6ifeline Denotes the life of actors+objects over
time during a sequence
4eresented by a vertical line below
each actor and object #normally dashed
line$
3or temorary object
lace 7 at the end of the lifeline at the
oint where the object is destroyed
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 22/46
Slide 22
Sequence Diagram
3ocus of control #activation bo*$
&eans the object is active and using
resources during that time eriod Denotes when an object is sending or
receiving messages
4eresented by a thin( longrectangular bo* overlaid onto a lifeline
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 23/46
Slide 23
Sequence Diagram
member:
LibraryMember book:Book
:Book
Copy
borrow(book)
ok = mayBorrow()
[ok] borrow(member) setTaken(member)
X-Axis (objets)
!-Axi s
( t i m e )
"bjetLi#e
LineMessa$e
%o&s o#
ontro'
Conition
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 24/46
Slide 24
Control Information
Condition
synta*, 898 e*ression 2:2 message;label
"he message is sent only if thecondition is true
[ok] borrow(member)
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 25/46
Slide 25
5lements of Sequence Diagram
obj1:Class
[x < 15] calculate()
obj2: Classmessage()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 26/46
Slide 26
Sequence Diagrams
obj1:Class
[x < 15] calculate()
obj2: Class
message()
obj3: Clas
[x > 20] calculate()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 27/46
Slide 27
Sequence Diagrams
Concurrency
obj1:Class
calculate()
obj2: Class
message()
obj3: Clas
calculate()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 28/46
Slide 28
5lements of Sequence Diagram
Control information Iteration
may have square brac!ets containing a
continuation condition #until$ secifyingthe condition that must be satisfied inorder to e*it the iteration and continuewith the sequence
may have an asteris! followed by squarebrac!ets containing an iteration #while orfor$ e*ression secifying the number ofiterations
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 29/46
Slide 29
Control Information
Iteration synta*, < 9 898 e*ression 8:2 :
message;label
"he message is sent many times to
ossibly multile receiver objects.
*draw()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 30/46
Slide 30
Control Information
Iteration e*amle
:*ri+er
*[until full] insert()
:B&s:Compo&n,ape :,ape
*draw()draw()
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 31/46
Slide 31
Control Information
"he control mechanisms of sequencediagrams suffice only for modelingsimle alternatives. Consider drawing several diagrams for
modeling comle* scenarios.
Don2t use sequence diagrams for
detailed modeling of algorithms #this isbetter done using activity diagrams, pseudo-code or state-charts$.
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 32/46
Slide 32
Sequence Diagrams
Creation and destruction of an object in sequence
diagrams are denoted by the stereotyes
==create>> and ==destroy>>
:Creator
<<create>>: Created Object
message()
<<destroy>>
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 33/46
Slide 33
Creating -bjects
0otation for creating an object on;the;fly
Send the ==create>> message tothe body of the object instance
-nce the object is created( it is
given a lifeline.0ow you can send and receive messages
with this object as you can any otherobject in the sequence diagram.
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 34/46
Slide 34
-bject Creation
'n object may create another object via a
<<create>> message.
:A :B
<<create>>
Constr&tor
:A
<<create>>
:B
re#erre
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 35/46
Slide 35
-bject Destruction
'n object may destroy another object via a<<destroy>> message.
'n object may destroy itself.
'void modeling object destruction unless
memory management is critical.
:A :B
<<destroy>>
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 36/46
Slide 36
getViolation(id)
Sequence Diagram
C'erk
:.io'ations
*ia'o$
:.io'ations
Contro''er
:.io'ations
*Broxy
lookupviewutton()
id=get!"()
+:Tra##i
.io'ation
display(v)
<<create>>
v
Look&p
Tra##i
.io'ation
*B is /&erie
an te res&'t
is ret&rne as
an objet
St f B ildi
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 37/46
Slide 37
Stes for Building
a Sequence Diagram
$ Set the conte*t
/$ Identify which objects and actors will articiate
1$ Set the lifeline for each object+actor
?$ 6ay out the messages from the to to the bottom ofthe diagram based on the order in which they are
sent
@$ 'dd the focus of control for each object2s or actor2s
lifeline
A$ )alidate the sequence diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 38/46
Slide 38
$ Set the conte*t.
a$ Select a use case.
b$ Decide the initiating actor.
Stes for Building a Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 39/46
Slide 39
/$ Identify the objects that mayarticiate in the imlementation ofthis use case by comleting thesulied message table.
a$ 6ist candidate objects.
$ Use case controller class
/$ Domain classes
1$ Database table classes
?$ Dislay screens or reorts
Stes for Building a Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 40/46
Slide 40
Stes for Building a Sequence Diagram
/$ Identify the objects #cont.$b$ 6ist candidate messages. #in message analysis table$
1) Examine each step in the normal scenario of the
use case description to determine the messages
needed to implement that step.
) !or each step:
$ Identify ste number.
/$ Determine messages needed to comlete this
ste.
1$ 3or each message( decide which class holds the
data for this action or erforms this action
") #a$e sure that the messages %ithin the ta&le are in the
same order as the normal scenario
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 41/46
Slide 41
Stes for Building a Sequence Diagram
/$ Identify the objects #cont.$
c$ Begin sequence diagram construction.$ Draw and label each of the identified actors and
objects across the to of the sequence diagram. /$ "he tyical order from left to right across the to is
the actor( rimary dislay screen class( rimaryuse case controller class( domain classes #in
order of access$( and other dislay screen classes#in order of access$
1$ Set the lifeline for each object+actor
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 42/46
Slide 42
?$ 6ay out the messages from the to to the
bottom of the diagram based on the order
in which they are sent.
a$ or!ing in sequential order of the messagetable( ma!e a message arrow with the
message name ointing to the owner class.
b$ Decide which object or actor initiates themessage and comlete the arrow to its lifeline.
c$ 'dd needed return messages.
d$ 'dd needed arameters and control
information.
Stes for Building a Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 43/46
Slide 43
@$ 'dd the focus of control #activation
bo*$ for each object2s or actor2s
lifeline.A$ )alidate the sequence diagram.
Stes for Building a Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 44/46
Slide 44
Sequence Diagrams
:Cas!"er
ma#e$e%&ale()
: &ystem
e$ter'tem("tem' *ua$t"ty)
descr"+t"o$ total
e$d&ale()
total
ma#e,ayme$t(amou$t)
c!a$ge due rece"+t
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 45/46
Slide 45
Sequence Diagram
8/16/2019 Aima SequenceDiagram Important
http://slidepdf.com/reader/full/aima-sequencediagram-important 46/46
Sequence Diagram
,Comiler 6in!er
Act!"C!#$%le
3ileSystem
L!a& F%les
Sa'e OBJ F%les
C!#$%le les
L%n
L!a& OBJ les
L%n OBJ les
*"%te E+E le