Week 5. Behavioural design and State Machine Diagrams
Behavioural Models
Behavioural models are models of the dynamic behaviour of a system as it is executing. They show what happens or is supposed to happen when a system is responds to stimulus from its environment. There are two different types of stimuli that a model can receive:
Link to original
- Data: some data arrives that has to be processed by the system.
- Events: some event happens that triggers system processing. Events may have associated data.
State Machine Models
State Machine Models model the behaviour of the system in response to external and internal events. They show the system’s responses to stimuli so are often used for modelling real-time systems. They show system states as nodes and events as arcs between nodes. When an event occurs, the system moves from one state to another.
Link to original
UML State Machine Diagram
State Machine Diagram (UML)
A state machine diagram is used to:
- Model the possible states of a system or object
- Show how the state transitions occur as a consequence of events
- Show what behaviour the system or object exhibits in each state
There are multiple components to a state machine diagram:
Link to original
State (UML State Machine)
State is the nodes of the state diagram.
- When a state is active, the object is in that state.
- All internal activities specified in the current state can be executed.
- An activity can consist of multiple actions.
Activity specifications:
entry / Activity(...): executed when the object enters the stateexit / Activity(...): executed when the object exits the statedo / Activity(...): executed while the object remains in this state
Link to original
Transition (UML State Machine)
A transition changes from one state to another.
The syntax used is as follows:
- Event (trigger): exogenous stimulus, can trigger state transition
- Guard (condition): boolean expression
- if the event occurs, guard is checked
- if guard is true:
- any activities in current state are terminated
- relevant exit activity is executed
- transition takes place
- if guard is false:
- no state transition takes place, event is discarded
- Activity (effect): sequence of actions executed during the state transition
There are two types of transition:
Link to originalEvent (UML State Machine)
There are different types of events we need to handle in a state diagram:
Link to original
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 e.g.
after(5 seconds)orwhen(time==16:00)Any receive event: occurs when any event occurs that does not trigger another transition from the active state e.g. keyword =
allCompletion event: generated automatically when everything to be done in the current state is completed
Change event: permanently checking whether a condition becomes true e.g.
when(x,y), after(90min)Below is a comparison between a change event and a guard:
Initial State (UML State Machine)
The initial state is the start of a state machine diagram.
- It is a pseudo-state.
- No incoming edges.
- If there is more than 1 outgoing edge, guards must be mutually exclusive and cover all possible cases to ensure that exactly one target state is reached.
- If initial state becomes active, the object immediately switches to the next state.
- No events allowed on the outgoing edges.
Link to original
Final State (UML State Machine)
The final state is a real state and marks the end of the sequence of states. Object can remain in a final state forever.
Link to original
Terminate Node (UML State Machine)
The terminate node is a pseudo-state that terminates the state machine. The modelled object ceases to exist.
Link to original
Decision Node (UML State Machine)
A decision node is a pseudo-state and is used to model alternative transitions.
Link to original
Parallelisation Node (UML State Machine)
A parallelisation node is a pseudo-state that splits control flow into multiple concurrent flows. There is one incoming edge and one or more outgoing.
Link to original
Synchronisation Node (UML State Machine)
A synchronisation node is a pseudo-state that merges multiple concurrent flows. There is one or more incoming edge and one outgoing edge.
Link to original
Example: Lecture Hall with Details

Example: Digital Clock

UML Best Practices
- Avoid crossing lines
- Depict crossing lines as a jump
- Avoid diagonal or curved lines
- Apply consistent sized symbols
- Align labels horizontally
- Arrange symbols symmetrically
- Organise diagrams left to right, top to bottom
- Show only what you have to show
- Re-organise large diagrams into several smaller ones
- Prefer single-page diagrams
- Apply language naming conventions on design diagrams
- Name common elements consistently across diagrams
- Indicate unknowns with a question mark
- Begin use-case names with a strong verb
- Imply timing consideration by stacking use cases
- Place your primary actor(s) in the top left corner of the diagram
- Name actors with a singular, domain-relevant name
- Associate each actor with one or more use case
- Name actor to model roles, not job titles
- Use <
to Indicate System Actors - Don’t allow actors to interact with one another
- Avoid more than two levels of use-case associations
- Place an included use case to the right of the invoking use case
- Place an extending use case below the parent use case
- Identify responsibilities on domain class models
- Indicate visibility only on design models
- Indicate types on analysis models only when the type is an actual requirement
- Be consistent with attribute names and types
- Do not name associations that have association classes
- Prefer complete single nouns for class names
- Name operations with strong verbs
- Name attributes with domain-based nouns
- Always indicate the multiplicity
- Avoid a multiplicity of ”*”
- Indicate role names on recursive associations
- Create a state machine diagram when behaviour differs based on state
- Question “black-hole” states: a black-hole state is one that has transitions into it but not out of it, something that should only be true of a final state
- Question “miracle” states: a miracle state is one that has transitions out of it but not into it, should only be true of a start state











