State Machines Flashcards
(21 cards)
What is the purpose of a state machine diagram?
To model:
- possible states of a system/object
- transitions between states triggered by events
- behaviour in each state
What activities can be defined within a state?
- entry/Activity: runs on entering the state
- exit/Activity: runs on exiting the state
- do/Activity: runs while in the state
What are the components of a transition?
- Event (trigger)
- Guard (boolean condition)
- Effect (actions during transition)
Internal vs External transitions
- Internal: No state change (e.g. event1 triggers Activity3 in state1)
- External: State change (e.g. event1 moves from state1 to state2)
Name 3 types of events
- Signal event (e.g. rightMouseDown)
- Call event (e.g. register(exam))
- Time event (e.g. after(5 secs))
What is an initial state?
A pseudo-state with:
- no incoming edges
- immediate transition to next state
- guards on outgoing edges must be mutually exclusive
Final state vs Terminate node
Final state: object remains here (end of lifecycle)
Terminate node: object is deleted
How does a decision node work?
Splits transitions into alternative paths with guards (e.g. [x > 0])
What does a parallelisation node do?
Splits control flow into concurrent sub-flows (1 input -> N outputs)
What is a synchronisation node?
Merges concurrent sub-flows into one (N inputs -> 1 output)
Change events vs Guards
Change event: continuously checked (e.g. when(x > y))
Guard: checked only when event occurs
Model a LectureHall with state Free and Occupied
[Free] –(occupy)–> [Occupied]
[Occupied] –(release)–> [Free]
Sketch states for exam registration
[Unregistered] –(register)–> [Registered]
[Registered] –(cancel)–> [Unregistered]
[Registered] –(pass)–> [Completed]
States
Represents conditions or situations during the lifecycle of an object
Transitions
Represents the movement from one state to another, triggered by events, guards or activities
Events
Triggers that cause a transition
Guards
Boolean conditions that must be true from a transition to occur
Activities
Actions executed when entering, exiting or during a state
Transition syntax
event[guard]/effect e.g. e1[x>5]/x++
When is a do-activity aborted?
When an event triggers a transition with no guard condition
What is a time event?
An event like when(date=31.12.2001) that triggers at a specific time