30
1

Se2 lec 13 uml state machines

Embed Size (px)

Citation preview

Page 1: Se2 lec 13  uml state machines

1

Page 2: Se2 lec 13  uml state machines

2

Important type of UML diagrams

A statechart diagram - shows the behavior of classes in response to

external or internal stimuli (Event). This diagram models the

dynamic flow of control from state to state within a system.

Statechart diagrams are useful to model reactive systems. Reactive

systems can be defined as a system that responds to external or

internal events.

State machine diagram - event-ordered behavior that specifies the

sequences of states an object/instance (of

class/interface/collaboration/…/system) goes through during its

lifetime; events trigger transitions and cause responses.

UML statecharts show states, transitions, events.

Page 3: Se2 lec 13  uml state machines

3

Use State Machines

at an early stage of software development

when behavior of an object (lifecycle) or operation is not

well understood yet

Do NOT use State Machines

when several objects are involved (interaction diagrams

are better)

Page 4: Se2 lec 13  uml state machines

4

A state diagram is a graph consisting of

States (a mode of the entity).

simple states

composite states (nested state diagrams)

State transitions connecting the states.

including events and actions.

State – Constraint or condition or situation during which an

object/instance may perform some activity; The state of an

object is characterized by the value of one or more of its

attributes.

State – Abstract view

The same response to the same stimuli

The same active behavior

Implementation

View certain attributes have certain values

Page 5: Se2 lec 13  uml state machines

5

Start state: State transition is executed immediately

during the creation of the object.

Only possible event: create (parameter)

Java: constructor (new)

Final State: destruction of the object

Page 6: Se2 lec 13  uml state machines

6

A transition connects two states and shows the flow of

control.

A transition can include a triggering event, a guard and

actions to be executed.

Transitions without event and guard are executed

immediately when an activity is finished respectively all sub

states were passed through.

Page 7: Se2 lec 13  uml state machines

7

An event is a phenomenon in space or time significant

for the modeled system.

An event takes place at certain point in time (has no

duration) has possibly parameters.

An event can appear synchronously or asynchronously.

Synchronous events:

• Call event: triggered by call

• Exception event: triggered by called object at return

Asynchronous events:

• Signal event: signal sent by other object.

• Change event: triggered by side effects on object

attributes.

• Time event: spontaneously triggered by Boolean guard

over time.

Page 8: Se2 lec 13  uml state machines

8

Signals are asynchronous, i.e., the sender does not wait until

the receiver received the signal or reacted on it.

A call event is triggered by a (synchronous) operation call.

Call events are synchronous, i.e., the sender waits until the

receiver reacted on the event.

The receiver can:

ignore the event (the event is lost),

execute its trigger event or

execute an operation.

Page 9: Se2 lec 13  uml state machines

9

Represents the dispatch of an operation

Name and parameter of the event must be compatible

to methods of the class.

Page 10: Se2 lec 13  uml state machines

10

A time event appears after the expiration of a time

period.

A change event occurs if a specific constraint is fulfilled.

The constraint is a Boolean

Expression on the attributes of the actual object.

Page 11: Se2 lec 13  uml state machines

11

Signals can be sent to other objects during a transition.

Page 12: Se2 lec 13  uml state machines

12

Possible actions:

send signal

perform call

perform access

Page 13: Se2 lec 13  uml state machines

13

A state can be refined hierarchically by composite

states.

Page 14: Se2 lec 13  uml state machines

14

In a state several sequences of sub states described by

own state machines can be performed concurrently.

Page 15: Se2 lec 13  uml state machines

15

Page 16: Se2 lec 13  uml state machines

16

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 17: Se2 lec 13  uml state machines

17

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 18: Se2 lec 13  uml state machines

18

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 19: Se2 lec 13  uml state machines

19

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 20: Se2 lec 13  uml state machines

20

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 21: Se2 lec 13  uml state machines

21

A chess game consists of alternate moves of Black and

White. White moves first.

The game can end both when it is White’s and when it is

Black’s turn.

The moving player can end the game: winning

(checkmate), loosing (resign), or with a draw.

Page 22: Se2 lec 13  uml state machines

22

The customer must pass

authentication before

withdrawing money.

Authentication is done by

checking a PIN.

The PIN can be corrector

not.

Unsuccessful attempts

are counted,

If the counter exceeds a

limit, the customer is

rejected.

Page 23: Se2 lec 13  uml state machines

23

The customer must pass

authentication before

withdrawing money.

Authentication is done by

checking a PIN.

The PIN can be corrector

not.

Unsuccessful attempts

are counted,

If the counter exceeds a

limit, the customer is

rejected.

Page 24: Se2 lec 13  uml state machines

24

The customer must pass

authentication before

withdrawing money.

Authentication is done by

checking a PIN.

The PIN can be corrector

not.

Unsuccessful attempts

are counted,

If the counter exceeds a

limit, the customer is

rejected.

Page 25: Se2 lec 13  uml state machines

25

The customer must pass

authentication before

withdrawing money.

Authentication is done by

checking a PIN.

The PIN can be corrector

not.

Unsuccessful attempts

are counted,

If the counter exceeds a

limit, the customer is

rejected.

Page 26: Se2 lec 13  uml state machines

26

The customer must pass

authentication before

withdrawing money.

Authentication is done by

checking a PIN.

The PIN can be corrector

not.

Unsuccessful attempts

are counted,

If the counter exceeds a

limit, the customer is

rejected.

Page 27: Se2 lec 13  uml state machines

27

The customer must

pass authentication

before withdrawing

money.

Authentication is

done by checking a

PIN.

The PIN can be

corrector not.

Unsuccessful

attempts are

counted,

If the counter

exceeds a limit, the

customer is rejected.

Page 28: Se2 lec 13  uml state machines

28

Page 29: Se2 lec 13  uml state machines

29

Page 30: Se2 lec 13  uml state machines

30