You are on page 1of 9

UML Sequence Diagrams

UML Sequence Diagrams 4 Use Case Analysis Sequence Diagram Basics Sequence Diagram Example From Sequence Diagrams to Class Diagrams

Michael Jones

UML Sequence Diagrams

Use Cases
Use Cases
title actors goal description

Use Case Diagrams


collection of Use Cases limited links between them no sequence <<uses>> and <<extends>>

Michael Jones

UML Sequence Diagrams

Use Case Descriptions


Tend to concentrate on sunny day scenario
everything goes right mixed metaphor: sunny day is the tip of the iceberg

Cannot convey event sequence very well


even if description is thoughtfully put together event dependencies not clear possible alternatives not clear

Sequence Diagrams
can show event dependencies

Michael Jones

UML Sequence Diagrams

Use Case Analysis


Look for objects
e.g., nouns objects will (probably) be seen as instances of some class domain nounsare objects, and their definitions are classes non-domain nouns become attributes

Describe objects
find the attributes and their types from the Use Case, the user,from general knowledge simple nouns (e.g., height) have simple types (e.g., int) computer complex nouns have object types (e.g., Date, String)

Construct Sequence Diagram

to clarify the sequence of actions actions will (probably) become methods

Michael Jones

UML Sequence Diagrams

Example
Use Case Description:

The customer asks the barman for a pint of beer. The barman pulls the pint, and then says the price. The customer hands over sufficient money. The barman rings up the price, puts the money in the till, and gives the customer any change. Example Objects and attributes
:Customer (objects are underlined with a colon before) cash - integer :Beer name - String price - currency sell by - Date
Michael Jones UML Sequence Diagrams 6

UML Sequence Diagrams Use Case Analysis 4 Sequence Diagram Basics Sequence Diagram Example From Sequence Diagrams to Class Diagrams

Michael Jones

UML Sequence Diagrams

Sequence Diagram Structure


Sequence diagrams are used alongside use case scenarios (descriptions) The potential objects are identified
not classes

Each object is at the top of a column


underlined, with a colon before the name

Column is either:
a line (where the object doesnt exist) two lines (forming a rectangle) where the object exists

Conditions and actions associated with the object are drawn in at the point were they occur in the use case
conditions are enclosed in square brackets actions have round brackets appended

Michael Jones

UML Sequence Diagrams

Sequence Diagrams Structure

System Border

:object1

:object2

:object3
new()

:object4

createNew()

local()

use case scenario written down here

check() [check=true] new()

Time

Michael Jones

UML Sequence Diagrams

Sequence Diagram Shapes

Fork - centralised

Stair - decentralised

operations can change order new operations may be added

Operations have strong connections performed in same order

Michael Jones

UML Sequence Diagrams

10

UML Sequence Diagrams Use Case Analysis Sequence Diagram Basics 4 Sequence Diagram Example From Sequence Diagrams to Class Diagrams

Michael Jones

UML Sequence Diagrams

11

Use Case Scenario


Domain: mail order video company Use Case: processing an order Actors: order processing administrator, customer Description: Customer sends in an order. Each video becomes

one line on the order. We supply as many as we have (up to the number requested), and reorder if necessary. We reorder when the stock falls below the reorder level for that stock item.

Michael Jones

UML Sequence Diagrams

12

Use Case Analysis


Objects and Attributes
NOTE: types should be included :order list of order line objects :order Line product number, description, unit price, quantity, price, VAT :video (stock item) product number, description, unit price, number of items in stock, reorder level, supplier(s) :reorder Item product number, supplier details, number to order

Michael Jones

UML Sequence Diagrams

13

Sequence Diagram Example - Reordering Videos


System Boundary
:order :order Line :video :reorder Item

* prepare() check() [check=true] getItems() needToReorder () format() [needToReorder = true] new()

Michael Jones

UML Sequence Diagrams

14

UML Sequence Diagrams Use Case Analysis Sequence Diagram Basics Sequence Diagram Example 4 From Sequence Diagrams to Class Diagrams

Michael Jones

UML Sequence Diagrams

15

Sequence Diagrams To Class Diagrams


Every domain noun becomes a class
same name as the objects, but with a capital letter e.g., :order is of type Order

Relationships between classes are defined by the Use Case analysis


e.g., Order has a one to many relationship with OrderLine e.g., OrderLine has a 0 or 1 relationship with ReorderItem

Attributes become (private) data

attributes which can be set from outside the class are called properties these have get and set methods other attributes each have a get method

Actions become methods


public if another object is involved, private otherwise

Michael Jones

UML Sequence Diagrams

16

Summary
Use Cases are analysed
to identify objects and their attributes to clarify the sequence of actions

Object and Attribute Identification

e.g., nouns - domain and non-domain e.g., from Use Cases, domain knowledge attribute types: can be simple or computer complex

Sequence Diagrams
each object has a time line showing creation, destruction actions represented as horizontal arrows action name has round brackets afterwards conditions are enclosed in square brackets

Class Diagrams can be constructed

from Use Case analysis and sequence diagrams


UML Sequence Diagrams 17

Michael Jones

You might also like