0% found this document useful (0 votes)
8 views31 pages

AMS2024 10b STM

Uploaded by

Fragy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views31 pages

AMS2024 10b STM

Uploaded by

Fragy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Behavioural Modelling

• Event Based Behavior => State Machines


• Black-blox view => Use Cases
• …also
• Flow-Based Behaviour
• Message Based Behaviour
Behaviour

State Machines
(Event-based
behavior)

BTW, why not some fun ;-)


https://www.youtube.com/watch?v=ABA3TGQVhTg
State Machine Diagrams
▪ A state machine diagram models the lifecycle of an entity.
▪ It specifies how state changes as a response to events.

3
States
▪ A state represents a situation where an invariant
condition holds.
▪ Invariant conditions are the properties that the
system satisfies in every reachable state.

▪ An invariant condition can be:


– static (e.g. waiting for an event)
or
– dynamic (e.g. performing a set of activities)

4
Entity Life Cycle
Transition diagrams define two kinds of
constraints on entity life cycles:
▪ The set of allowed states. This is a
static constraint.
▪ The set of legal sequences of these
states. This is a transition
constraint because it involves two
or more states.

The life cycle of an entity e at time t is


the sequence of states activated by e
since its creation until t.

A life cycle is said to be complete if its


last state is always a final state.

5
state machines
▪ Entity Behavior can be modeled as state machines.
▪ In principle, not all entities need to be modeled as state machines.
▪ Transition diagrams are an effective mechanism for defining the
behavior of the instances of some entity types.
▪ However, they are not intended to be the best mechanism in all
cases. This is one reason why some conceptual modeling languages
offer several ways to model behavior.
Conceptual Modeling of Information Systems (chapter 13, page 301)

6
An
example
of a State
Machine
Diagram

http://www.sparxsystems.com/uml_tool_guide/uml_dictionary/statediagram.html 7
States…
▪ The State Machine concept can be used for modeling discrete
behavior through finite state transition systems.
▪ The state machine represents behavior as the state history of
an object in terms of its transitions and states.
▪ The activities that are invoked during the transition, entry, and
exit of the states, are specified along with the associated event
and guard conditions.
▪ A composite state has nested states that can be sequential or
concurrent

8
Simples States and Composite States
There are two types of states
– Simple States

– Composite States: a state that contains other states (sub-


states), allowing the construction of hierarchical (or
composite) state machines

9
State Transitions
▪ A transition is based on: std for a Lamp
– a source state s,
– an event d,
– a target state t.

▪ When the state machine is in state s and it


receives event d for which there is a transition to
state t, then the transition is said to be enabled.
– The event d is called the trigger of the transition.
– One says that d fires the transition.

▪ If the machine receives an event


which is not the trigger of any
transition then the machine is
unaffected by the event.

10
State Transitions
▪ An example of a transition of a rental car is:
– Source state: available
– Trigger: domain event Pick-Up
– Target state: in use

The meaning is that:


▪ When a car is in the state available …
– and the domain event Pick-Up of that car occurs,
– Then, the new state of the car is in use.

Pick-up
availabl
in use
e
11
State Transitions and Guards
▪ Example of a transition of a rent car with a guard is:
– Source state: available
– Guard: the car is not booked for maintenance
– Trigger: domain event Rental Request
– Target state: rented
▪ The meaning is that:
– when a car is in the state Available
– and the domain event Rental Request occurs,
– if the car is not booked for maintenance
– then the new state of the car is rented.

rental request [~rented]


availabl
rented
e

12
State Transitions

Trigger Target
Conditio Initial
State State
n
Source
State

End
State

Conceptual Modeling of Information Systems (chapter 13, page 306) 13


Example: Telephone (partial)
Example: Telephone
Pseudostates
▪ A pseudostate is an abstract state used to represent
the start, end or internally to connect other stated of
the diagram.
▪ The following pseudostates are defined in
UML/SysML.

16
Pseudostates
▪ Initial state – Represents the first state
that occurs when entering a region. An
initial state must be present in each region.

▪ Terminal/Final state – Represents the final


state of a region and ends the execution of
all states within that region.

▪ History – Specifies that, when the


statechart leaves and then returns to a
region, the statechart enters the substate
that was active when the statechart left
the region.
Cf. shallow and deep history on the book.
17
Pseudostates

18
Pseudostates

▪ Join - serve to merge several


transitions, with no guards,
emanating from one or more
source states.

▪ Fork - serve to split an incoming


transition, with no guard, into two
or more transitions.

19
Pseudostates - Junction

Junction
▪ A pseudostate with at least one incoming and one outgoing transition. In general, the
incoming transitions have a trigger, and both the incoming and the outgoing transitions have a
guard.
▪ A junction provides a means to simplify two or more transitions by factoring out their common
parts. For example, a junction can be used to converge multiple incoming transitions into a single
outgoing transition representing a shared transition path.
▪ Conversely, a junction can be used to split an incoming transition into multiple outgoing transition
segments with different guard conditions.

20
Pseudostates - Junction

Example of a junction to simplify four transitions:


▪ The transition from State0 to State3 triggered by e2 and guarded by the condition [“b<0” and “a=5”]
▪ The transition from State0 to State4 triggered by e2 and guarded by the condition [“b<0” and “a>7”]
▪ The transition from State1 to State2 triggered by e1 and guarded by the condition [“b<0” and “a<0”]
▪ …

21
Pseudostates - Choice

Choice e1[c1]
▪ Similar to a junction, but the [c2]
guards of the outgoing transitions
are evaluated once the incoming [c3]
e1[c1]
transitions have produced their
effect.
▪ Choices are considered as
dynamic conditional branches
because the target state is not
known until the operations
associated with the incoming
transitions have been completed.

22
Example: Car rental

23
Detailing states

The problem of this


approach: it forces to
change the high level
conceptualization (notion
of “InUse” state is lost,
reducing semantics…)…

24
Detailing states

With a Composite
State, “InUse” state
is kept, stressing its
semantics!!!

25
Parallelism

26
States and Behaviours

▪ Behaviours
– entry/…action…
– do/…action…
– exit/…action….

27
State Diagrams as Event-based Behaviour

28
H20
http://media.tiscali.co.uk/images/feeds/hutchinson/ency/c00503.jpg

29
An example …

30
An example …

31

You might also like