L7 State Machines Flashcards
What is a State Machine Diagram?
It models the behaviour of a thing, specifying the sequence of states that it goes through during its lifetime in response to events.
‘Thing’ could be system, subsystem or class.
What do State Machines/diagrams/charts model?
Dynamic behaviour
Explain what a State Machine Diagrams is
- Models what could happen when an object receives a message
- Include events that lead to object changing state
- The same objects can behave differently depending on the states and events.
What is a “State”
Condition object stays in for some time, during which it behaves in the same way. But may respond differently to the same trigger (event) in different states.
What is a “Transition”
From one state to the next; may have a trigger, a guard and an effect
What is a “Trigger”
- External, instantaneous stimulus
- A signal, an event, a change in some condition, or the passage of time
What is a “Guard”
A condition which must be true in order for the trigger to cause the transition
What is an “Event”
An action that occurs as a result of the transition.
Actions can be associated with the transition itself, with entry to or exit from a state, or can occur continually during a state (“do” activity)
LABEL ON TRANSITION IS
trigger (list of input data) [guard] / effect
What are the three types of Event Types
- Signal event (Receipt of a signal e.g., rightmousedown, sendSMS(message)
- Call Event (Operation call, e.g., occupy(user,lectureHall), register(exam)
- Time Event (Time-based state transition)
What is the Composite States
- State machines can be nested, so that we can hide a submachine/substate at some level of abstraction.
- What appears as a single state at one level can be viewed in more detail -we can “zoom in”.
- Substates can be shown in place, or hidden with use of composite icon.
What is the Concurrent States?
- If a composite state machine has two or more regions, their submachines operate concurrently.
- State of the object is a pair (or tuple) of substrates
- Entry and exit can be synchronized by fork and join
State Notation
Modelling the state of a bank account….
Modelling the state of a lecture hall….
Event Types
● Signal event
Receipt of a signal e.g., rightmousedown, sendSMS(message)
● Call event
Operation call, e.g., occupy(user,lectureHall), register(exam)
● Time event
Time-based state transition
- Relative: based on the time of the occurrence of the event, e.g., after(5 seconds)
- Absolute, e.g., when(time==16:00), when(date==20150101)
Changing from one state to another….
Example: login part of a system
Building a State Diagram
Britton and Dokes recommends:
1. Identify the events that affect an object
2. Identify the possible different states, including start and stop states
3. Check whether events are conditional
4. Identify any actions the object performs in response to an event
5. Begin the diagram from the start state
6. Build the diagram systematically through events and states
7. Check for super states/composite states
Building an example State Diagram
A Human Resources system has the following requirements:
- A job application is created when an application form is received and details recorded.
- The application is read by a manager and either shortlisted or rejected
- If rejected the JA is filed for 6 months then discarded
- If shortlisted, interview details are sent out and the interview usually confirmed by the candidate
- After interview the applicant may not be successful and a rejection letter is sent and the JA filed for 6 months then discarded
- If the applicant is offered the job an offer letter is sent out
- If the applicant declines the JA is filed for 6 months then discarded
- If the offer is accepted other procedures take over the processing
- The applicant may withdraw at any point