Docsity

Understanding Sequence Diagrams: A Tutorial on Modeling Object Interactions, Slides of Object Oriented Analysis and Design

Partial preview of the text

Download Understanding Sequence Diagrams: A Tutorial on Modeling Object Interactions and more Slides Object Oriented Analysis and Design in PDF only on Docsity!

Sequence Diagrams 1

Agenda

  • Interaction Diagrams
  • A First Look at Sequence Diagrams
  • Objects
  • Messages
  • Control Information
  • Examples

Sequence Diagrams 2

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.

Sequence Diagrams 4

Interaction Diagrams (Cont.)

  • UML
    • Collaboration Diagrams
      • Emphasizes structural relations between objects
    • Sequence Diagram
      • The subject of this tutorial

Sequence Diagrams 5

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.

Sequence Diagrams 7

A Sequence Diagram

member: LibraryMember book:Book^

:Book Copy

borrow(book) ok = mayBorrow()

[ok] borrow(member) (^) setTaken(member)

X-Axis (objects)

Y-Axis (time)^ Life^ Object

message Line Activation box condition

Sequence Diagrams 8

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

Sequence Diagrams 10

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.

Sequence Diagrams 11

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()

Sequence Diagrams 13

Object Creation

  • An object may create another object via a

<> message.

:A :B

<>

Constructor

:A

<> (^) :B

Preferred

Sequence Diagrams 14

Object Destruction

  • An object may destroy another object via a

<> message.

  • An object may destroy itself.
  • Avoid modeling object destruction unless memory management is critical. :A :B <>

Sequence Diagrams 16

Control Information (Cont.)

  • Iteration examples:

:Driver

*[until full] insert()

:Bus

The syntax of expressions is not a standard

:CompoundShape :Shape draw() *draw()

Sequence Diagrams 17

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 ).

Sequence Diagrams 19

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