Software Diagrams

profilemartinpham
SE311SequenceDiagram.pptx

UML Sequence Diagram

UML sequence diagrams

Sequence diagram: an "interaction diagram" that models scenarios executing in the system

perhaps 2nd most used UML diagram (behind class diagram)

Relation of UML diagrams to other exercises:

CRC cards -> class diagram

Use cases -> sequence diagrams

One sequence diagram can show multiple scenarios (user stories)

2

Key parts of a sequence diag.

participant: an object or entity that acts in the sequence diagram

sequence diagram starts with an unattached "found message" arrow

message: communication between participant objects

the axes in a sequence diagram:

horizontal: which object/participant is acting

vertical: time (down -> forward in time)

3

Sequence diag. from use case

4

Representing objects

squares with object type, optionally preceded by object name and colon

write object's name if it clarifies the diagram

object's "life line" represented by dashed vert. line

5

Messages between objects

message (method call) indicated by horizontal arrow to other object

write message name and arguments above arrow

dashed arrow back indicates return

different arrowheads for normal / concurrent (asynchronous) methods

6

Lifetime of objects

creation: arrow with 'new' written above it

notice that an object created after the start of the scenario appears lower than the others

deletion: an X at bottom of object's lifeline

Java doesn't explicitly delete objects; they fall out of scope and are garbage-collected

7

Indicating method calls

activation: thick box over object's life line; drawn when object's method is on the stack

either that object is running its code, or it is on the stack waiting for another object's method to finish

nest to indicate recursion

8

Activation

Nesting

Indicating selection and loops

frame: box around part of a sequence diagram to indicate selection or loop

if -> (opt) [condition]

if/else -> (alt) [condition], separated by horiz. dashed line

loop -> (loop) [condition or items to loop over]

9

[

balance

<>

0

]

opt

[

balance

<

100

.

00

]

[

balance

>

=

100

.

00

]

alt

[

balance

<

0

]

loop

linking sequence diagrams

if one sequence diagram is too large or refers to another diagram, indicate it with either:

an unfinished arrow and comment

a "ref" frame that names the other diagram

when would this occur in our system?

10

Example sequence diagram

11

Scenario (User Story)

 

A player rolls the dice and gets a 6. The player moves 6 cells. The player lands on a cell that is an un-owned property. The player’s turn is over.

You begin to create a sequence diagram by writing a scenario and highlighting all the nouns in the scenario. The nouns generally become the objects that appear in the columns. For example, consider the following scenario. The unique nouns are circled. Each of these nouns is likely to become an object (though not all do, as you will see with the noun “turn”).

[click] This figure shows a possible sequence diagram for this scenario.

Conditional Logic

If the player lands on a cell that is an un-owned property, the player’s turn is over.

If the player lands on a cell that is owned, the player must pay rent to the owner of the property.

Then, the player’s turn is over.

Conditional logic may also be expressed in a sequence diagram as a guard. In this way, a sequence diagram can express a set of scenarios in a more general way.

Consider this scenario and the sequence diagram in the figure that can be used for this scenario:

A player rolls the dice and moves the number of cells indicated on the dice. [click] If the player lands on a cell that is an un-owned property, the player’s turn is over. [click] If the player lands on a cell that is owned, the player must pay rent to the owner of the property. Then, the player’s turn is over.

You can use the “else” part of the sequence diagram to express what could be thought of as a second scenario in which the player lands on an owned property and has to pay rent.

13

(De)centralized system control

What can you say about the control flow of each of the following systems?

centralized?

distributed?

14

Why not just code it?

Sequence diagrams can be somewhat close to the code level. So why not just code up that algorithm rather than drawing it as a sequence diagram?

15

a good sequence diagram is still a bit above the level of the real code (not EVERY line of code is drawn on diagram)

sequence diagrams are language-agnostic (can be implemented in many different languages

non-coders can do sequence diagrams

easier to do sequence diagrams as a team

can see many objects/classes at a time on same page (visual bandwidth)

Verify customer credit

refCustomer Info

Approved?

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

Verify customer credit

ref

Customer Info

Approved?

sd Example

loop

StoreFrontCartInventory

AddItem

ReserveItem

PlaceItemInOrder

Checkout

ProcessOrder

ConfirmOrder

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

[guard]

sd Example

StoreFront

Cart

Inventory

loop

AddItem

ReserveItem

PlaceItemInOrder

Checkout

ProcessOrder

ConfirmOrder

Player

DiceCellProperty

rollDice

DiceValue(6)

MoveCell(6)

isOwnedProperty

isOwnedProperty(False)

rollDice

DiceValue(6)

MoveCell(6)

isOwnedProperty

isOwnedProperty(False)

Player

Dice

Cell

Property

Player

Dice

CellProperty

rollDice

DiceValue(n)

MoveCells(n)

[isOwnedProperty]

isOwnedProperty(False)

isOwnedProperty(True,owner)

Owner

PayOwner

[else]

Player

Dice

Cell

Property

rollDice

DiceValue(n)

MoveCells(n)

[isOwnedProperty]

isOwnedProperty(False)

isOwnedProperty(True,owner)

Owner

PayOwner

[else]