Open In App

State Machine Diagrams | Unified Modeling Language (UML)

A State Machine 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.



1. What is a State Machine 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.



Let’s understand State Machine Diagram with the help of an example:

Example:

The State Machine Diagram above shows the different states in which the verification sub-system or class exist for a particular system.

2. Basic components and notations of a State Machine diagram

2.1. Initial state

We use a black filled circle represent the initial state of a System or a Class.

2.2. Transition

We use a solid arrow to represent the transition or change of control from one state to another. The arrow is labelled with the event which causes the change in state.

2.3. State

We use a rounded rectangle to represent a state. A state represents the conditions or circumstances of an object of a class at an instant of time.

2.4. Fork

We use a rounded solid rectangular bar to represent a Fork notation with incoming arrow from the parent state and outgoing arrows towards the newly created states. We use the fork notation to represent a state splitting into two or more concurrent states.

2.5. Join

We use a rounded solid rectangular bar to represent a Join notation with incoming arrows from the joining states and outgoing arrow towards the common goal state. We use the join notation when two or more states concurrently converge into one on the occurrence of an event or events.

2.6. Self transition

We use a solid arrow pointing back to the state itself to represent a self transition. There might be scenarios when the state of the object does not change upon the occurrence of an event. We use self transitions to represent such cases.

2.7. Composite state

We use a rounded rectangle to represent a composite state also. We represent a state with internal activities using a composite state.

2.8. Final State

We use a filled circle within a circle notation to represent the final state in a state machine diagram.

3. How to draw a State Machine diagram in UML?

Below are the steps of how to draw the State Machine Diagram in UML:

Step1. Identify the System:

Step2. Identify Initial and Final States:

Step3. Identify Possible States:

Step4. Label Triggering Events:

Step5. Draw the Diagram with appropriate notations:

Let’s understand State Machine diagram with the help of an example, ie for an online order :

The UML diagrams we draw depend on the system we aim to represent. Here is just an example of how an online ordering system might look like :

  1. On the event of an order being received, we transit from our initial state to Unprocessed order state.
  2. The unprocessed order is then checked.
  3. If the order is rejected, we transit to the Rejected Order state.
  4. If the order is accepted and we have the items available we transit to the fulfilled order state.
  5. However if the items are not available we transit to the Pending Order state.
  6. After the order is fulfilled, we transit to the final state. In this example, we merge the two states i.e. Fulfilled order and Rejected order into one final state.

Note: Here we could have also treated fulfilled order and rejected order as final states separately.

4. UseCases of State Machine Diagram

5. What are the Differences between a State Machine Diagram and a Flowchart?

What is a Flowchart?

An algorithm is like a set of clear instructions to solve a problem, and a flowchart is a picture that shows those instructions.

Example:

A manufacturer uses a flow chart to explain and illustrate how a particular product is manufactured.

State Machine Diagram VS Flow Chart?

State Machine Diagram

Flow Chart

An State Machine Diagram is associated with the UML(Unified Modelling Language)

A Flow Chart is associated with the programming.

The basic purpose of a state machine diagram is to portray various changes in state of the class and not the processes or commands causing the changes.

A flowchart on the other hand portrays the processes or commands that on execution change the state of class or an object of the class.

Primarily used for systems, emphasizing their states and transitions.

Often used for processes, procedures, or algorithms involving actions and decisions.

6. Conclusion

State Machine Diagrams in UML are like pictures that tell us how things change in a system. They show the different situations a system can be in and how it moves between them. These diagrams help us understand what events make these changes happen. Whether it’s for designing software or explaining how something works, State Machine Diagrams are like visual guides that make it easier to see and understand how a system behaves in different situations.


Article Tags :