What is a state diagram in UML?
A state machine is any device that stores the status of an object at a given time and can change status or cause other actions based on the input it receives. States refer to the different combinations of information that an object can hold, not how the object behaves. In order to understand the different states of an object, you might want to visualize all of the possible states and show how an object gets to each state, and you can do so with a UML state diagram.
Each state diagram typically begins with a dark circle that indicates the initial state and ends with a bordered circle that denotes the final state. However, despite having clear start and end points, state diagrams are not necessarily the best tool for capturing an overall progression of events. Rather, they illustrate specific kinds of behavior—in particular, shifts from one state to another.
State diagrams mainly depict states and transitions. States are represented with rectangles with rounded corners that are labeled with the name of the state. Transitions are marked with arrows that flow from one state to another, showing how the states change. Below, you can see both these elements at work in a basic diagram for student life. Our UML diagram tool can help you design any custom state machine diagram.
State diagram applications
Like most UML diagrams, state diagrams have several uses. The main applications are as follows:
Depicting event-driven objects in a reactive system.
Illustrating use case scenarios in a business context.
Describing how an object moves through various states within its lifetime.
Showing the overall behavior of a state machine or the behavior of a related set of state machines.
State diagram symbols and components
You can include many different shapes in a state diagram, particularly if you choose to combine it with another diagram. This list summarizes the most common shapes you may encounter.
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.
A diamond symbol that indicates a dynamic condition with branched potential results.
An instance that triggers a transition, labeled above the applicable transition arrow. In this case, “classes end” is the event that triggers the end of the “Being taught” state and the beginning of the “Final exams” state.
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.
A marker for the first state in the process, shown by a dark circle with a transition arrow.
A Boolean condition that allows or stops a transition, written above the transition arrow.
A rectangle with rounded corners that indicates the current nature of an object.
A state contained within a composite state's region. In the university state machine diagram found below, “Open for enrollment” is a substate in the larger “Enrollment” composite state.
A circle with a dot in it that indicates that a process is terminated.
An arrow running from one state to another that indicates a changing state.
A behavior that results when a state transitions, written above the transition arrow.
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.
State diagram examples
Calendar availability state diagram example
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.