Lecture 12 - State Diagram
Lecture 12 - State Diagram
>
Modeling
State Diagrams
2
> State Notation
3
> State machine diagram
➢Model the behaviour of the system in response to external and
internal events.
➢A state machine diagram is a graph consisting of:
• States (simple states or composite states)
• State transitions connecting the states
4
> Simple State
➢A simple state is a state that does not have substates - it has
no regions and it has no submachine states.
Simple state
Waiting for Simple state Waiting for
Customer Input. Customer Input with
name and internal activities
compartments.
5
> Composite State
➢This refers to a state contained within a composite state’s region.
6
> Initial and Final States
➢The initial state of a state machine diagram, known as an initial
pseudo-state, is indicated with a solid circle. A transition from this
state will show the first real state
7
> Example: Order State Diagram
dispatch
8
> Transitions
➢Transition lines depict the movement from one state to another.
Each transition line is labeled with the event that causes the
transition.
9
> Transitions
➢The label on the connector / transition usually follows the
format trigger [guard conditions] /actions. The trigger should
generally be defined, but the guard condition and action can be
omitted if they are not required.
10
> Trigger/ Guard/ Effect
➢"Trigger" is the cause of the transition, which could be a signal, an
event, a change in some condition, or the passage of time.
➢"Guard" is a condition which must be true in order for the trigger to
cause the transition.
➢"Effect" is an action which will be invoked directly on the object
that owns the state machine as a result of the transition.
11
> Events / Triggers
➢Events appear in the internal transition compartment of a state or
on a transition between states. An event may be one of four types:
➢Signal event - corresponding to the arrival of an asynchronous
message or signal
➢Call event - corresponding to the arrival of a procedural call to an
operation
➢Time event - a time event occurs after a specified time has
elapsed
➢Change event - a change event occurs whenever a specified
condition is met
12
> Choice Pseudo-State
➢A choice pseudo-state is shown as a diamond with one transition
arriving and two or more transitions leaving.
13
> Choice pseudo-state
14
> Fork / Join
➢The segments outgoing from a fork vertex must not have guards
or triggers.
➢The transitions entering a join vertex cannot have guards or
triggers.
Fork splits transition into two Join merges transitions into single
transitions transition
15
> Concurrent Regions
➢A state may be divided into regions containing sub-states that
exist and execute concurrently.
16
> Example: Super Mario
17
> State Diagram
Number of ways that the
different states of the
player avatar may be
handled
○ Small Form
○ Superb Form
○ Shooter Form
18
> Example: Course state diagram
19
> Example: Course state diagram
20
> Example: Course lifecycle
21
>
➢State charts
• For describing a full system behavior
• How it reacts to events
• For describing the full behavior of an
active class to external method calls
➢Activity diagrams
• For describing processes
• E.g. how the use cases execution is
sequenced
• For describing algorithms
• As for sequence diagrams: may be used
to show interactions between different
objects
22
>
23
> Example: Microwave oven
24
> States for the microwave oven
State Description
Waiting The oven is waiting for input. The display shows the current time.
Half power The oven power is set to 300 watts. The display shows ‘Half power’.
Full power The oven power is set to 600 watts. The display shows ‘Full power’.
Set time The cooking time is set to the user’s input value. The display shows
the cooking time selected and is updated as the time is set.
Disabled Oven operation is disabled for safety. Interior oven light is on.
Display shows ‘Not ready’.
Enabled Oven operation is enabled. Interior oven light is off. Display shows
‘Ready to cook’.
Operation Oven in operation. Interior oven light is on. Display shows the timer
countdown. On completion of cooking, the buzzer is sounded for five
seconds. Oven light is on. Display shows ‘Cooking complete’ while
buzzer is sounding.
25
> Stimulus for the microwave oven (b)
stimuli Description
Half power The user has pressed the half-power button.
26
> State diagram of a microwave oven
27
> Microwave oven operation
28
>
29