State Chart Diagram
State Chart Diagram
A state diagram is used to represent the condition of the system or part of the system at finite
instances of time. It’s a behavioral diagram and it represents the behavior using finite state
transitions. State diagrams are also referred to as State machines and State-chart Diagrams.
These terms are often used interchangeably. So simply, a state diagram is used to model the
dynamic behavior of a class in response to time and changing external stimuli. We can say that
each and every class has a state but we don’t model every class using State diagrams. We
prefer to model the states with three or more states.
Firstly let us understand what are Behavior diagrams? There are two types of diagrams in
UML :
1. Structure Diagrams – Used to model the static structure of a system, for example- class
diagram, package diagram, object diagram, deployment diagram etc.
2. Behavior diagram – Used to model the dynamic change in the system over time. They are
used to model and construct the functionality of a system. So, a behavior diagram simply
guides us through the functionality of the system using Use case diagrams, Interaction
diagrams, Activity diagrams and State diagrams.
A statechart diagram shows a state machine, focusing on the flow of control from state to state. A
state machine is a behavior that specifies the sequences of states an object goes through during its
lifetime in response to events, together with its responses to those events. What distinguishes a state
chart diagram from other diagrams is its content.
When we model the dynamic aspects of a system, a class or a use case, we will use statechart
diagrams to model reactive (event-driven) objects.
Types of State
The UML consist of three states:
The primary focus of the state machine diagram is to depict the states of a system. These states are
essential while drawing a state transition diagram. The objects, states, and events due to which the
state transition occurs must be acknowledged before the implementation of a state machine diagram.
Following are the steps that are to be incorporated while drawing a state machine diagram:
1. A unique and understandable name should be assigned to the state transition that describes
the behavior of the system.
2. Out of multiple objects, only the essential objects are implemented.
3. A proper name should be given to the events and the transitions.
It portrays the changes underwent by an object from the start to the end. It basically envisions how
triggering an event can cause a change within the system.
Initially, the ATM is turned off. After the power supply is turned on, the ATM starts performing the
startup action and enters into the Self Test state. If the test fails, the ATM will enter into the Out
Of Service state, or it will undergo a triggerless transition to the Idle state. This is the state where
the customer waits for the interaction.
Whenever the customer inserts the bank or credit card in the ATM's card reader, the ATM state
changes from Idle to Serving Customer, the entry action readCard is performed after entering
into Serving Customer state. Since the customer can cancel the transaction at any instant, so the
transition from Serving Customer state back to the Idle state could be triggered by cancel event.
Here the Serving Customer is a composite state with sequential substates that are Customer
Authentication, Selecting Transaction, and Transaction.
Composite state
A state that has substates nested into it. See the university state
diagram example below. “Enrollment” is the composite state in this example
because it encompasses various substates in the enrollment process.
Choice pseudostate
Event
Exit point
The point at which an object escapes the composite state or state machine,
denoted by a circle with an X through it. The exit point is typically used if the
process is not completed but has to be escaped for some error or other issue.
First state
A marker for the first state in the process, shown by a dark circle with a transition
arrow.
Guard
A Boolean condition that allows or stops a transition, written above the transition
arrow.
State
A rectangle with rounded corners that indicates the current nature of an object.
Substate
Terminator
Transition
An arrow running from one state to another that indicates a changing state.
Transitional behavior
A behavior that results when a state transitions, written above the transition
arrow.
Trigger
A type of message that actively moves an object from state to state, written
above the transition arrow. In this example, “Issue with reservation” is the trigger
that would send the person to the airport travel agency instead of the next step in
the process.
This state machine diagram example shows the process by which a person sets an
appointment on their calendar. In the “Check date” composite state, the system
checks the calendar for availability in a few different substates. If the time is not
available on the calendar, the process will be escaped. If the calendar shows
availability, however, the appointment will be added to the calendar.
University state diagram example
This state diagram shows the process of enrollment and classes at a university.
The composite state “Enrollment” is made up of various substates that will lead
students through the enrollment process. Once the student has enrolled, they will
proceed to “Being taught” and finally to “Final exams.”
Airport check-in state diagram example
The following example simplifies the steps required to check in at an airport. For
airlines, a state diagram can help to streamline processes and eliminate
unnecessary steps.