A state diagram describes how an object behaves when it encounters events within a system. Also known as state machine diagrams, state diagrams have their origin in the field of computer science. They describe the behavior of a system while considering all possible states the objects within that system can have when outside events occur. State diagrams were originally conceptualized by David Harel.
Software developers and embedded system engineers commonly use state diagrams to visualize the entire life cycle of objects to get a better and clearer understanding of the big picture. However, state diagrams can also reveal the changes between states of business data objects in a system, and show the events that cause the objects to enter certain states. In other words, state diagrams help us model the dynamic flow of an object from state to state within a system.
State diagrams typically describe the states of an object, the transitions between the different states and the events that trigger those transitions. Thinking through objects in a system and their respective states can also help identify missing requirements.
How To Draw A State Diagram
To model the behavior of an object in a system during its lifetime, there are certain steps the analyst should follow:
- Define States: A state is a condition in which an object may be during its lifetime in a system. To make the different states easier to identify, start with the initial and final state of an object and then define the intermediate states
- Describe States: To help others better understand the states defined in the previous step, it’s important to completely describe all the states an object can go through.
- Draw Transitions: In the third step, draw lines to indicate changes from one state to another.
- Define Transition Triggers: Specify what must happen in order for a transition from one state to another to take place.
- Define Guard Conditions: Sometimes, we want a transition from one state to another to take place only if it meets certain conditions, which act as constraints.
As shown in the sample diagram above, state diagrams are created using standardized symbols and notations.
- Filled circle: To represent an initial state, we draw a filled circle. Most state diagrams begin with an initial state and expand on it.
- Filled circle with an outer ring: State diagrams conclude with a filled circle together with an outer ring, which represents a final state.
- Rectangle: A simple state is represented by a rectangle with rounded edges. Inside the rounded rectangle is the state name and incoming/outgoing transitions.
- Arrow: We draw an arrow between two states to represent the transition from one state to another. Every transition has a trigger event as well as a condition and an action.
A product for example, can be in different states throughout its lifecycle on an e-commerce website: “introduced”, “on shelf”, “in cart”, “bought”, “delivered” and so on.
State diagrams are sometimes used in conjunction with state tables. A typical state table has all initial states organized in a single column on the left side, while all target states are in a single row at the very top of the table. The cells of a state table then show all the possible transitions and whether they are valid. For business analysts, it’s recommended to begin with a state table, and use it for guidance when creating a state diagram. See a piece from Seilevel on how state tables can be used.