UML Statecharts

Emmanuel Fleury

B1-201

fleury@cs.aau.dk

Outline

Motivations

State-Diagrams

Finite State Machines

Statecharts

UML Statecharts

Modelling Tools

Motivations

Motivations

A computer system can be seen

as a reactive system

Black Box

Input1

Input2

Input3

Output1

Output2

Output3

System to be modelled

Our Goal ?

Represents
Computer Systems

in an “efficient” way !

The Problem

Global Understanding of the system

Global Analysis of the system

Flexibility/Adaptability of the system

Modularity of the system

Maintainability of the system

Computer systems are more and more

complex and this complexity prevent:

Success Criteria

Human Readable (a visual formalism)

Concise

Formal

Abstract

Just as expressive as needed
(important properties can be checked)

Good Properties to get:

State-Diagrams

Why States ?

Computer systems are naturally organized

in “states”. Where each state is an

abstraction for a position in the process

of achieving the task of the system.

Idle

Processing

Wait

Input1

Output1

ε

State-Diagrams

Labelled Directed Graphs

Hypergraphs

Hierarchical Graphs

Higraphs

Labelled Directed Graphs

Q a finite set of states;

A a (possibly infinite) alphabet;

T⊆QxAxQ a finite set of transitions.

C

a

A

B

d

c

c

b

A Labelled Directed Graph

is a triplet (Q, A, T):

Example

Idle

Received

message

Wait

SYN/ACK

get_message

send_ACK

get_SYN/ACK

send_ACK

Advantages/Drawbacks

Good Points:

Human readable

Formal

Bad Points:

Not concise enough !!!

We need more abstraction !!!

Hypergraphs

Q a finite set of states;

A a (possibly infinite) alphabet;

H⊆QxAxP(Q) a finite set of hyper-edges.

An Hypergraph is a triplet (Q, A, H):

Try to factorize the number of edges

and generalize the notion of graphs !

Nice in theory but unusable in practice !

Hierarchical Graphs

Notion of Hierarchy among the states

Allows Clustering, Refining and Zooming !

Clustering

C

a

c

c

b

A

B

d

C

a

b

A

B

d

c

D

Clustering

Using states hierarchy to

factorize behaviours

Refining

C

a

b

A

B

d

c

D

C

a

b

c

D

Refining

Using state hierarchy to implement

“a posteriori” the

internal behaviour of a state

A

B

Zooming In/Out

C

a

b

A

B

d

c

D

C

a

b

c

D

A

B

Zoom In

Using state hierarchy to

hide/unveil implementation's details

Zoom Out

Formal Definition

Q a finite set of states;

E⊆QxQ a finite set of edges;

>⊆QxQ the hierarchical relations in between states.

A Hierarchical Graph

is a triplet (Q, E, >):

But...

A lot of semantics problems !!!

Higraphs

Introduced by David Harel in 1987

for Avionic Systems Modelling.

higraphs = graphs + depth + orthogonality

Superstates

A state which contain state(s)

All of them have a default entry

There are two types
of superstates:

AND-States

OR-States

Default Entry

One and only one for each superstate.

Indicate the default initial state whenever the superstate is entered.

OR-States

At any given time, we are in

one and only one OR-State.

1

2

3

4

5

AND-States

A

C

D

B

E

F

Parallel composition via split of a superstate (dashed line)

Each split is said to be an OR-state.

No limitation in the number of OR-states.

AND-States

A

C

D

B

E

F

1

1

1

1

2

2

2

2

At any given time, we are in

every AND-States.

AND-States

A

C

D

B

A,D

B,D

B,C

A,C

⇔

Semantically equivalent to the cartesian product

of each automaton contained in one AND-state

Intend to reduce the number of states !

Crossing Dashed Line Edges

Exit

Exit

Enter

Enter

⇔

What should happen here ????

Multiple-Crossing Edges

Each edge cross a superset border only once.

Redundant edges are pruned.

Intended to remove unnecessary complexity of the model

Symbolic Representation

B

H

I

D

E

A

F

G

C

A

B

D

E

C

F

G

H

I

OR-State

AND-State

1

1

2

2

2

2

3

3

4

4

Example

And... Something's missing

Black Box

Input1

Input2

Input3

Output1

Output2

Output3

We still need to handle input/output messages !!!

And higraphs do not provide any mechanism for this...

Finite State Machines

Acceptors/Recognizers

- Finite Automata

- Büchi Automata

- ... etc ...

Automata

aaabcccad

YES

NO

The acceptor can decide if a

word is in his language or not

Acceptors/Recognizers

s0

s1

s2

Q a finite set of states;

A a (possibly infinite) alphabet;

T⊆QxAxQ a finite set of edges

s0 is the initial state

F⊆Q the set of accepting states

An acceptor is a 5-tuple (Q, A,T,s0,F):

The accepting condition change depending

on the kind of acceptor we consider.

Finite Automata

s0

s1

s2

Q a finite set of states;

A a (possibly infinite) alphabet;

T⊆QxAxQ a finite set of edges

s0 is the initial state

F⊆Q the set of accepting states

A Finite automata is a 5-tuple (Q, A,T,s0,F):

The word should end in

one final state !

Büchi Automata

s0

s1

s2

Q a finite set of states;

A a (possibly infinite) alphabet;

T⊆QxAxQ a finite set of edges

s0 is the initial state

F⊆Q the set of accepting states

A Büchi automata is a 5-tuple (Q, A,T,s0,F):

The word should go infinitely

often in one final state

Still not quite that...

We want more than a “YES” or “NO” answer.

We want to output another word.

Black Box

Input1

Input2

Input3

Output1

Output2

Output3

Automata

aaabcc

ccbaaa

Transducers

Transducers

- Moore Machines

- Mealy Machines

- ... etc ...

Automata

aaabcc

ccbaaa

Transducers

Q a finite set of states;

Ain a (possibly infinite) input alphabet;

Aout a (possibly infinite) output alphabet;

T⊆QxAinxQ a finite set of edges

O⊆QxAinxAout a set of outputs

s0 is the initial state

A Transducer is a 6-tuple (Q, Ain,Aout,T,O,s0):

There are several ways to define

the output function.

Moore Machines

s0

s1

s2

a

c

b

Q a finite set of states;

Ain a (possibly infinite) input alphabet;

Aout a (possibly infinite) output alphabet;

T⊆QxAinxQ a finite set of edges

O⊆QxAout a set of outputs

s0 is the initial state

A Transducer is a 6-tuple (Q, Ain,Aout,T,O,s0):

The output depends in which state you are in

Example (Moore Machine)

Input

Output1

Output2

Off

On

click

click

click

Input String: click, click, click, ...

Output String: 0, 1, 1, 1, 0, ...

1

1

0

Mealy Machines

s0

s1

s2

Q a finite set of states;

Ain a (possibly infinite) input alphabet;

Aout a (possibly infinite) output alphabet;

T⊆QxAinxQ a finite set of edges

O⊆QxAinxAout a set of outputs

s0 is the initial state

A Transducer is a 6-tuple (Q, Ain,Aout,T,O,s0):

The output depends on which transition you are taking

Example (Mealy Machine)

Input / Output

Off

On

click / 1

click / 0

click / 1

Input String: click, click, click, ...

Output String: 1, 1, 1, 0, 1, 0, ...

Statecharts

Statecharts in a Nutshell

What are the Statecharts ?

Represent the behavioural view of the system.

Visual formalism for describing states and transitions in modular way.

What is the purpose of using Statecharts ?

To suppress and organize details.

Best if graphical. The clarity they provide can be lost if they are represented in tabular form.

Advantages of Statecharts

A hierarchical structure to reduce complexity and support abstraction

AND/OR superstates

Concurrency & Orthogonality

Compact & Expressive

Global Communication Mechanism

Formal enough to avoid ambiguity
(code generation is possible)

Two Types of Models

2 Types of statechart development:

Harel’s Statechart

Developed by David Harel.

First developed for function-oriented systems.

Later extended for OO systems with few changes.

UML Statechart

Developed by Object Management Group (OMG).

Extend the properties of Harel’s statecharts with some new features.

Harel's

Statecharts

Harel's Statecharts

Harel's Statecharts =

state-diagrams + depth + orthogonality + broadcast

Harel's Statecharts is an higraph with mealy machine's like communication and extra macro-commands like:

(Deep/Shallow) History

Joins and Forks

Conditional

Selection

Timeout

Synchronization/Broadcast

A

C

D

e

b/f

B

a/b

g

E

F

f/h

i

Mealy machine's communication which allows:

Synchronizations

Broadcasts

History Entries

2 Types of History Entries:

Shallow History (H): Represents the most recently entered state at the same level.

Deep History (H*): Represents the most recently visited state whatever how deep is the state.

An History Entry give the most recently

visited state of the entered superstate

Shallow History

A

C

D

B

E

F

H

Deep History

A

C

D

B

E

F

H*

Joins & Forks

a

b

a

a

b

Take care of the guards !!!

Join

Fork

Condition & Selection

Condition (C):
When entering the superstate, a condition is checked and a sub-state is chosen.

Selection (S):
When entering the superstate, a variable is checked and a sub-state is chosen.

Condition

A

C

D

B

E

F

C

i>3

j=3

i=3

Selection

A

C

D

B

E

F

S

var=1

var=2

var=3

Time-out

<2sec

timeout

But, time is not inherent in the model

So be careful !

Force to leave the (super)state

after the time-out has expired

through the timeout transition.

But...

Still some semantics problems !!!

Problems of Harel's Model

Semantics:
Many papers published with flaws or ambiguities. None giving the complete formal semantics

Notion of Time:
Each transition is supposed to take no time which is an unrealistic assumption in RT systems

Determinism:
The model is easily made non-deterministic which is a problem at code generation

... etc ...

UML

Statecharts

What is UML ?

UML = Unified Modelling Language

Introduced by the Object Management Group (OMG)

in 1997 as a standard modelling language for

object-oriented applications

UML defines a the syntax and the semantics of

a set of visual formalisms (diagrams) which gives

different perspectives of a software system

UML 1.0

Use Case Diagram: Interactions between the system and the users

Class Diagram: Class hierarchy and data layout over the classes

State Diagram: Behaviour of the system abstracted as a set of states and transitions

Communication Diagram: Object interactions

Sequence Diagram: Time sequence of object interactions

Component Diagram: High-level packaged structure of the code

Deployment Diagram: Physical architecture and deployment of components on the hardware architecture

UML 2.0

Structural Modelling Diagrams

Package Diagrams

Class Diagrams

Object Diagrams

Composite Structure Diagrams

Component Diagrams

Deployment Diagrams

Behavioural Modelling Diagrams

Use Case Diagrams

Activity Diagrams

State Machine Diagrams

Communication Diagrams

Sequence Diagrams

Timing Diagrams

Interaction Overview Diagrams

UML Statecharts

UML Statecharts inherits:
AND/OR-states, (Shallow/Deep) History, Fork/Join, Condition, Time-out.

UML Statecharts introduces:
Synch, Terminal, Junction, Stub.

Harel's Statecharts was introduced in UML

with modification of the semantics

and some additional elements

New Properties

Transitions are supposed to take an “insignificant” amount of time... (sigh!)

The model doesn't support overlapping superstates (clearer semantics)

Events can carry parameters and variables

Introduce a “pseudo-states” class
(history, fork, join, condition, ...)

Starting/Ending

Initial pseudo-state

Final pseudo-state

End of subtask

Synchronization (Fork/Join)

Join

Fork

Used to enter or exit AND-states

Transitions

Trigger[Guard]/Effect

Off

On

click[i<5]/1

click[i=0]/0

click[i>5]/1

Decision (Branch/Merge)

Branch

[i<10]

[i=10]

Merge

[i<10]

[i=10]

Take care of the guards !!!

Hiding Superstates

= Something is hidden

Pseudo-states

Stub

Merge Junction

Choice Point

Junction

Initial/Default

Deep History

Shallow History

Name

Symbol

H

H*

Join

Fork

Synch

Terminal

Conditional

Name

Symbol

C

OR

T

OR

*

OR

n

Problems of UML Model

Semantics:
Many papers published with flaws or ambiguities. None giving the complete formal semantics

Notion of Time:
Each transition is supposed to take no time which is an unrealistic assumption in RT systems

Determinism:
The model is easily made non-deterministic which is a problem at code generation

... etc ...

None of the problems have been solved !

Modelling Tools

VisualSTATE 5.1

VisualSTATE Components

6 Components:

Navigator: Project Manager

Designer: Statecharts diagrams editor

Verificator: Model Verifier

Validator: Model Simulator and Tester

Coder: Code Generator

Documenter: Documentation Writer

VisualSTATE Features

From the original Statecharts

Superstates

Mealy transitions (I/O)

Orthogonality

Default Entry states

(Deep) History states

Added to the formalism

Variables (VS_INT, VS_UINT, VS_FLOAT, ...)

Signals (m, ^m)

C functions on transitions

VisualSTATE Transitions

Condition Side

Action Side

Ev(p),S1,[(x<7)||(y>10)]

[z=MAX],A1(x,y),S4,^SIG

Trigger

State Condition

Guard Expression

Assignment

Function

Force State

Signal

Statemate 4.0

Statemate is development plate-form for object-oriented embedded

systems applications.

* Enables complete systems design at the highest level

* Eliminates ambiguities common in written specifications

* Validates system behaviour early in the design process

* Generates an executable specification of the system

* Links designers, developers, and users for collaboration on a design,

increasing the level of communication and cooperation

* Simplifies understanding of operation with animation of graphical models

during code execution

* Accelerates the rapid prototyping process by providing C or Ada code

for virtual and physical prototypes

* Produces production quality code generation from the design model

* Enables hardware/software co-specification

* Automatically generates complete, consistent, and formal documentation

Rhapsody 6.0

Rhapsody is an UML 2.0 based Model-Driven Development environment for systems and software engineering. It allows to specify systems and software design graphically, execute and validate the system as building it, and ultimately produce full production code from the model for the target system.

* Environment for Systems and Software Development

* Requirements Modelling

* Design-level Debugging on Target

* Directly Deployable C, C++, and Ada Code Generation

* Automatic Test Vector Generation

Questions ?

Bluesquares

Lecture Template

2004-10-21T11:07:41