sequence diagrams by zvika gutterman adam carmi. agenda interaction diagrams a first look at...

23
Sequence Diagrams By Zvika Gutterman Adam Carmi

Post on 21-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Sequence Diagrams

By

Zvika Gutterman

Adam Carmi

Page 2: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Agenda

• Interaction Diagrams

• A First Look at Sequence Diagrams

• Objects

• Messages

• Control Information

• Examples

Page 3: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Interaction Diagrams

• A series of diagrams describing the dynamic behavior of an object-oriented system.– A set of messages exchanged among a set of

objects within a context to accomplish a purpose.

• Often used to model the way a use case is realized through a sequence of messages between objects.

Page 4: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Interaction Diagrams (Cont.)

• The purpose of Interaction diagrams is to:– Model interactions between objects– Assist in understanding how a system (a use

case) actually works– Verify that a use case description can be

supported by the existing classes– Identify responsibilities/operations and assign

them to classes

Page 5: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Interaction Diagrams (Cont.)

• UML – Collaboration Diagrams

• Emphasizes structural relations between objects

– Sequence Diagram• The subject of this tutorial

Page 6: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

A First Look at Sequence Diagrams

• Illustrates how objects interacts with each other.

• Emphasizes time ordering of messages.

• Can model simple sequential flow, branching, iteration, recursion and concurrency.

Page 7: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

A Sequence Diagram

member:LibraryMember

book:Book:BookCopy

borrow(book)ok = mayBorrow()

[ok] borrow(member)setTaken(member)

Page 8: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

A Sequence Diagram

member:LibraryMember

book:Book:BookCopy

borrow(book)ok = mayBorrow()

[ok] borrow(member)setTaken(member)

X-Axis (objects)

Y-A

xis (tim

e)

ObjectLife Linemessage

Activation box

condition

Page 9: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Object

• Object naming:– syntax: [instanceName][:className]

– Name classes consistently with your class diagram (same classes).

– Include instance names when objects are referred to in messages or when several objects of the same type exist in the diagram.

• The Life-Line represents the object’s life during the interaction

myBirthdy:Date

Page 10: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Messages

• An interaction between two objects is performed as a message sent from one object to another.– Most often implemented by a simple

operation call.

– Can be an actual message sent through some communication mechanism, either over the network or internally on a computer.

• Inter-process communication (Signaling, …)

• Remote Procedure Call (RMI, CORBA, …)

Page 11: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Messages (Cont.)

• If object obj1 sends a message to another object obj2 an association must exist between those two objects:– Structural dependency

– obj2 is in the global scope of obj1

– obj2 is in the local scope of obj1 (method argument)

– obj1 and obj2 are the same object

Page 12: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Messages (Cont.)

• A message is represented by an arrow between the life lines of two objects.– Self calls are also allowed– The time required by the receiver object to process the

message is denoted by an activation-box.

• A message is labeled at minimum with the message name.– Arguments and control information (conditions,

iteration) may be included.– Prefer using a brief textual description whenever an

actor is the source or the target of a message.

Page 13: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Message Types

Synchronous

Asynchronous

Simple

Create

Destroy

<<create>>

<<destroy>>

Page 14: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Synchronous Messages

• Nested flow of control, typically implemented as an operation call.– The routine that handles the message is

completed before the caller resumes execution.

:A :B

doYouUnderstand()

Caller Blocked

return (optional)yes

Page 15: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Return Values

• Optionally indicated using a dashed arrow with a label indicating the return value.– Don’t model a return value when it is obvious

what is being returned, e.g. getTotal()– Model a return value only when you need to

refer to it elsewhere, e.g. as a parameter passed in another message.

– Prefer modeling return values as part of a method invocation, e.g. ok = isValid()

Page 16: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Object Creation

• An object may create another object via a <<create>> message.

:A :B

<<create>>

Constructor

:A

<<create>> :B

Preferred

Page 17: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Object Destruction

• An object may destroy another object via a <<destroy>> message.– An object may destroy itself.

– Avoid modeling object destruction unless memory management is critical.

:A :B

<<destroy>>

Page 18: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Asynchronous Messages

• Used for modeling concurrent systems.• Caller does not wait for the message to be handled

before it continues to execute.– As if the call returns immediately

• Active objects own an execution thread and can initiate control activity.

• An asynchronous message can:– Create a new thread (a new activation record)– Create a new object– Communicate with a thread that is already running.

Page 19: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Control information

• Condition– syntax: ‘[‘ expression ’]’ message-label– The message is sent only if the condition is true– example:

• Iteration– syntax: * [ ‘[‘ expression ‘]’ ] message-label– The message is sent many times to possibly

multiple receiver objects.

[ok] borrow(member)

Page 20: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Control Information (Cont.)

• Iteration examples:

:Driver

*[until full] insert()

:Bus

The syntax of expressions is not a standard

:CompoundShape :Shape

*draw()draw()

Page 21: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

Control Information (Cont.)

• The control mechanisms of sequence diagrams suffice only for modeling simple alternatives. – Consider drawing several diagrams for

modeling complex scenarios.– Don’t use sequence diagrams for detailed

modeling of algorithms (this is better done using activity diagrams, pseudo-code or state-charts).

Page 22: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

getViolation(id)

Example 1

Clerk

:ViolationsDialog

:ViolationsController

:ViolationsDBProxy

lookupviewButton()

id=getID()

v:TrafficViolation

display(v)

<<create>>

v

Lookup Traffic Violation

May be a pseudo-method

DB is queried and the result is returned as an object

Page 23: Sequence Diagrams By Zvika Gutterman Adam Carmi. Agenda Interaction Diagrams A First Look at Sequence Diagrams Objects Messages Control Information Examples

print(doc,client)

Example 2

Client

:PrintServer :Queue:PrinterProxy

enqueue(job)

status

Printing A Document

job=dequeue()

[job]print(job.doc)

[job] done(status)

Repeated forever with 1 min interludes

Active object