21
State and Sequence Diagrams [email protected] Modelling dynamic information So far we have seen: Use Case Diagrams – requirements capture, interface modelling Use Case Scripts – more detailed and with alternate, less common cases noted Class Diagrams – description of the structure of a class and possibly its relationship with other classes These are static descriptions of software

Modelling dynamic information

  • Upload
    aulii

  • View
    25

  • Download
    2

Embed Size (px)

DESCRIPTION

Modelling dynamic information. So far we have seen: Use Case Diagrams – requirements capture, interface modelling Use Case Scripts – more detailed and with alternate, less common cases noted - PowerPoint PPT Presentation

Citation preview

Page 1: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Modelling dynamic information

So far we have seen:Use Case Diagrams – requirements capture,

interface modellingUse Case Scripts – more detailed and with

alternate, less common cases notedClass Diagrams – description of the structure of a

class and possibly its relationship with other classes

These are static descriptions of software

Page 2: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Dynamic Modelling

In order to model the dynamic (run-time) relationships we need different tools

The UML provides us with State Diagrams and Object Sequence Diagrams (OSD)

There are others...

Page 3: Modelling dynamic information

State and Sequence Diagrams

[email protected]

State Diagrams

What do state diagrams describe?When things happenThe life-cycle of an instance (object)

How useful are they?Often but not always usedLogically links a Class Diagram to a State Diagram

– events are operations on classes in the Class Diagram

Clarifies the internal state and external behaviour of an object

Page 4: Modelling dynamic information

State and Sequence Diagrams

[email protected]

State Diagram Elements

start point states end point(s)

transitions (labeled with events)

PaidUnpaidpay

createinvoice

destroyinvoice

Page 5: Modelling dynamic information

State and Sequence Diagrams

[email protected]

State Diagram examples

A chess game classWhite takes the first turn, then turns alternateAfter any move “mate” or “stalemate” may occur

Black's turn

White's turn

Black wins

Draw

White wins

mate

mate

stalemate

stalematemove

move

Page 6: Modelling dynamic information

State and Sequence Diagrams

[email protected]

State Change Events

A state describes a particular condition of an object for a period of time – it waits for an event to change state or to “fire”

Events can be of the following types:Change – occurs when a condition becomes true

i.e. a booleanCall/Signal – occurs when an object receives a call

for one of its operations (from another object or from itself)

Time trigger

Page 7: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Guards

Known as a guard conditionIt guards the transition i.e. the transition can

only take place if the guard condition evaluates to true

Guards are constraints on behaviourExample in Visio

Page 8: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Event Types

Kinds of eventsreceipt of a call on an operation - a messagereceipt of an explicit signal from another object - a

messagea condition becoming truepassage of a designated period of time

Basic semantics about event labelled transitions

events are triggers that activate state transitionsif an event occurs and guard is false then the event is

ignored (events are not stored)

Page 9: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Visio Support – State Chart

Page 10: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Inside States

Three kinds of internal content for a stateThese represent the internal activities or state

activities that are executed in that stateEntry actionsExit actionsInternal transitions - do not cause a state change

All the above represent the operations for the class that is being modelled

Page 11: Modelling dynamic information

State and Sequence Diagrams

[email protected]

How to find States

A state chart captures all the possible responses of a single object to all the Use Cases in which it is involved

So a cross reference of which of the Use Cases a class is involved in will give you possible states for an object of that class

The state chart can be seen as a description of all the possible life-cycles for an objectProvides a dynamic view of a class

Page 12: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Object Sequence Diagrams

OSDs depict a Use Case Script visually but also show the classes (objects) used in the script

They show the sequence of object interactionRead the Visio tutorials for detailed information

on the Sequence ChartThe next slides show example Sequence

Charts

Page 13: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Simple Example

Mary : HotelGuest

324 : Room fred : Cleaner hilton : Hotel Fred X : CleanerXMary X : Guest

1: leaving

2: I am vacating

3: clean me

4: clean room 324

5: done romm 324

6: you are clean

7: I am available

Page 14: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Page 15: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Sequence Diagrams

PurposeCaptures the

behaviour of a single use case - how messages are sent within a use case

Shows how objects interact with each other - show how they send and receive messages

Focuses on time

Name : Class

SyntaxObject

Time

message

Page 16: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Sequence Diagram

Example

Nokia : TelephoneSystem

Caller : Person Receiver : Person

1: pick up

2: dial tone

3: dial4: ring

5: ring notification

6: pick up

Page 17: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Sequence Diagram

Types of messagessimple

flat flow of control - control is passed without describing any details

synchronousnested flow of control - operation callhandling of the message is completed before the caller

resumes execution

asynchronousthere is no explicit return to the callerthe sender continues to execute after sending the

message without waiting for it to be handled

Page 18: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Sequence Diagram

ActivationTime during which object

performs an action either directly or through another object (subcontractor)

ReturnImplicit

Explicit

: A : B

1:

: A : B

Page 19: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Drawing an OSD

Select a Use Case for which you have a ScriptMake a list of classes which appear on that

script (you may have done this already if you have created a Class Diagram)

Use Visio to create a new Sequence DiagramDo the simple things first and build it upPlace the objects (classes) on the diagramThink about the order that you put them in

Page 20: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Drawing an OSD

When creating messages, for the first draft just use the simple message call shapeRefine to synchronous or asynchronous at the 2nd

draft

Finally, put the rectangle duration box (operation life) overlay onto the timeline for each object

Then review it and do a 2nd draft

Page 21: Modelling dynamic information

State and Sequence Diagrams

[email protected]

Self-paced tutorial

Create a State Diagram in Visio for the third version of the example Soup Menu applicationHints: states include ingredient choice (three types) and action choiceWhat kind of transitions are there? - write down a listHints: remember that each transition is a flow from one state to anotherFinally, what events/actions are there for the transitions in your list?