STID3023 Week11-StateDiagram
STID3023 Week11-StateDiagram
STID3023 Week11-StateDiagram
Diagram
Week 14
Lecture Outline
State machine Diagrams
State machine syntax/Notation
State
Event
Transition
Initial/Final State
Learning Objective
create stack
push
Empty
pop/error
Loaded
pop[ empty ]
pop
pop[ not empty ]
push[full ]
Full
push / error
aState
AN INITIAL STATE
A FINAL STATE
AN EVENT
A TRANSITION
anEvent
States
Waiting on an event, or
States> Notation
State name
States> Eg :
after(5 seconds)
Idle
do action()
Active
States
State has several parts:
1.
Name
Textual string that distinguishes the state from other states
2.
Entry/exit actions
Actions when entering and leaving the state
Syntax: entry/action, exit/action
3.
Internal transitions
When events are processed internally, without leaving a state.
The entry/exit actions are not executed.
Syntax: event/action,
4.
Activity
When in a state, an object is not necessarily idle it may be
continuously performing some operation.
Syntax: do/activity,
5.
Substates
Nested state/composite states (sequential/concurrent
substates)
States
State has several parts:
Internal
transition
compartment
Name
compartment
State Name
entry / action
expression
exit/ action expression
do / activity
include / submachine
Initial/Final States
final state
Initial state
after(5 seconds)
Idle
do action()
Active
1.
Final state
2.
Events
Types of Event
No
.
1.
Description of Events
A change event occurs when some condition is
satisfied (a Boolean condition becomes true).
Change event vs Guard Condition (GC)
2.
Syntax
When
(exp)
after
(time)
When(11:50pm)/selfTest()
Time event
after(5 seconds)
/displayMain()
Idle
do action()
Active
Types of Event
No.
3.
Description of Events
Syntax
Idle
op(a:T)
parameter
pressButton(withdraw)
Active
Types of Event
No.
4.
Description of Events
Syntax
sname
(a:T)
Wait for
Fax
incoming call
Receive
Fax
Transition
Transition
There may be an action associated with a triggered
Transition
Transition has 5 parts:
1.
Source state
eventName[guard condition]
eventName[guard condition]/action
[guard condition]
4.
Action
Transition
after(2 secs)/send o.isAlive
Idle
noise
Searching
targetAt(p)
[isThreat]/t.a
ddTarget(p)
Engaging
contact
Tracking
Transition
Send signal
Time event
Idle
noise
Event trigger
Triggerless
transition
Searching
Engaging
GC
targetAt(p)
[isThreat]/t.a
ddTarget(p)
action
final state
contact
Tracking
Display
Do/display
current time
mode_button
Set hours
Do/display
hours
mode_button
mode_button
Set minutes
Do/display
minutes
Example: CourseOffering
(CO)
Initially, a CO must be initialized with a lecturer assigned
to the CO.
A CO object may be open(able to add student) or closed
(when achieve maximum number of students already
assigned to the CO object). Assume that the max no. of
students that can be assigned to a CO is 10 students.
Whenever there are students register to a CO, ask
CourseRegister object(external object) to create the CO
into the list.
The CO object must count the no. of student added to the
CO.
A CO may also be cancelled at any time during the
semester.
Initialization
State machine
diagram for
CourseOffering
object.
cancel
Canceled
[ count = 10 ]
cancel
Closed
Exercise 1
Create a state machine diagram to show the state
Clue
Create a state machine diagram to show the state
Exercise 2
Develop a State machine for the following specification of a CD
player.
The CD Player contains a CD drawer with three functional
buttons: Load, Play and Stop.
Load Button shall open the CD drawer if currently the CD
drawer is closed and vice versa.
Stop Button will stop the CD player being played. If this
button is pressed without any CD being played, it shouldnt
give any response.
Play Button will play the CD. If this button is being pressed
with the drawer is still open, the drawer shall close it first
before playing the CD.
Additional information:
The user can press the Off button at anytime to stop the
operation.
It is assumed that the CD drawer is closed in the initial state.
Answer #1
Start
New
submission
being
evaluated
When[ suitable = No ]
accepted
rejected
End
Answer #2
Start
When[ button=On ]
When[ button=stop ]
When[ button=stop ]
When[ button=load ]
Closed
When[ button=load ]
When[ button=play ]
When[ button=stop ]
Open
Playing
When[ button=Off ]
When[ button=Off ]
When[ button=Off ]
End