The Wayback Machine - https://web.archive.org/web/20241006142031/https://www.geeksforgeeks.org/unified-modeling-language-uml-state-diagrams/
Open In App

State Machine Diagrams | Unified Modeling Language (UML)

Last Updated : 04 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

state-machine-diagram-banner

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.

  • State Machine diagrams are also referred to as State Machines Diagrams and State-Chart Diagrams.
  • These terms are often used interchangeably. So simply, a state machine 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 Machine diagrams.
  • We prefer to model the states with three or more states.

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

Example:

A-State-Machine-Diagram-for-user-verification

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

For an in-depth understanding of State Machine Diagrams and how to apply them, the System Design Course covers these concepts thoroughly with real-world examples.

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.

initial-State-(1)

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.

transition

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.

state

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.

fork-(1)

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.

join-(1)

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.

self-transition

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.

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.

final-state-(1)

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

State-Machine-Diagrams-Unified-Modeling-Language-(UML)

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

Step1. Identify the System:

  • Understand what your diagram is representing.
  • Whether it’s a machine, a process, or any object, know what different situations or conditions it might go through.

Step2. Identify Initial and Final States:

  • Figure out where your system starts (initial state) and where it ends (final state).
  • These are like the beginning and the end points of your system’s journey.

Step3. Identify Possible States:

  • Think about all the different situations your system can be in.
  • These are like the various phases or conditions it experiences.
  • Use boundary values to guide you in defining these states.

Step4. Label Triggering Events:

  • Understand what causes your system to move from one state to another.
  • These causes or conditions are the events.
  • Label each transition with what makes it happen.

Step5. Draw the Diagram with appropriate notations:

  • Now, take all this information and draw it out.
  • Use rectangles for states, arrows for transitions, and circles or rounded rectangles for initial and final states.
  • Be sure to connect everything in a way that makes sense.

Let’s understand State Machine diagram with the help of an example, ie for an online order :
state-machine-diagram-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

  • State Machine Diagrams are particularly useful for modeling and visualizing the dynamic behavior of a system.
  • They showcase how a system responds to events and transitions between different states.
  • We use it to state the events responsible for change in state (we do not show what processes cause those events).
  • Objects go through different states during their existence, and these diagrams help in illustrating these states and the transitions between them.
  • In embedded systems, where hardware interacts with software to perform tasks, State Machine Diagrams are valuable for representing the control logic and behavior of the system.

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.

  • When we’re writing computer programs, a flowchart helps us map out the steps of the algorithm to solve the problem.
  • Non programmers use Flow charts to model workflows.
  • We can call a flowchart a primitive version of an activity diagram.
  • Business processes where decision making is involved is expressed using a flow chart.

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.



Previous Article
Next Article

Similar Reads

Class Diagrams vs Object Diagrams | Unified Modeling Language(UML)
UML class diagrams and object diagrams are the key tools for understanding the structure of a system, yet they serve distinct purposes. The differences between UML class diagrams and object diagrams provide insights into their unique functionalities, use cases, and how they complement each other in the software development process. What are Class D
3 min read
Behavioral Diagrams | Unified Modeling Language(UML)
Complex applications need collaboration and planning from multiple teams and hence require a clear and concise way to communicate amongst them. So UML becomes essential to communicate with non-programmers about essential requirements, functionalities, and processes of the system. UML is linked with object-oriented design and analysis. UML makes use
7 min read
Object Diagrams | Unified Modeling Language (UML)
Object diagrams are a visual representation in UML (Unified Modeling Language) that illustrates the instances of classes and their relationships within a system at a specific point in time. They display objects, their attributes, and the links between them, providing a snapshot of the system's structure during execution. Since object diagrams depic
8 min read
Structural Diagrams | Unified Modeling Language(UML)
Complex applications need collaboration and planning from multiple teams and hence require a clear and concise way to communicate amongst them. So UML becomes essential to communicate with non-programmers about essential requirements, functionalities, and processes of the system. UML is linked with object-oriented design and analysis. UML makes use
6 min read
Interaction Overview Diagrams | Unified Modeling Language (UML)
Interaction Overview Diagrams (IODs) in UML (Unified Modeling Language) provide a high-level view of the interactions between various components or objects in a system. They are used to visualize the flow of control and interactions within a system, showing how different parts of the system communicate and collaborate to achieve a specific goal. Im
8 min read
Collaboration Diagrams | Unified Modeling Language(UML)
In UML (Unified Modeling Language), a Collaboration Diagram is a type of Interaction Diagram that visualizes the interactions and relationships between objects in a system. It shows how objects collaborate to achieve a specific task or behavior. Collaboration diagrams are used to model the dynamic behavior of a system and illustrate the flow of mes
8 min read
Unified Modeling Language (UML) Diagrams
Unified Modeling Language (UML) is a general-purpose modeling language. The main aim of UML is to define a standard way to visualize the way a system has been designed. It is quite similar to blueprints used in other fields of engineering. UML is not a programming language , it is rather a visual language. Understanding and effectively using UML ca
15 min read
Use Case Diagrams | Unified Modeling Language (UML)
A Use Case Diagram is a vital tool in system design, it provides a visual representation of how users interact with a system. It serves as a blueprint for understanding the functional requirements of a system from a user's perspective, aiding in the communication between stakeholders and guiding the development process. Important Topics for the Use
10 min read
Sequence Diagrams | Unified Modeling Language (UML)
Unified Modelling Language (UML) is a modeling language in the field of software engineering that aims to set standard ways to visualize the design of a system. UML guides the creation of multiple types of diagrams such as interaction, structure, and behavior diagrams. A sequence diagram is the most commonly used interaction diagram. Interaction di
11 min read
Activity Diagrams | Unified Modeling Language (UML)
Activity Diagrams are used to illustrate the flow of control in a system and refer to the steps involved in the execution of a use case. It is a type of behavioral diagram and we can depict both sequential processing and concurrent processing of activities using an activity diagram ie an activity diagram focuses on the condition of flow and the seq
9 min read
Conceptual Model of the Unified Modeling Language (UML)
The Unified Modeling Language (UML) is a standard visual language for describing and modelling software blueprints. The UML is more than just a graphical language. Stated formally, the UML is for: Visualizing, Specifying, Constructing, and Documenting. The artifacts of a software-intensive system (particularly systems built using the object-oriente
3 min read
Deployment Diagram in Unified Modeling Language(UML)
A Deployment Diagram in software engineering is a type of Structural UML Diagram that shows the physical deployment of software components on hardware nodes. It illustrates the mapping of software components onto the physical resources of a system, such as servers, processors, storage devices, and network infrastructure. Important Topics for the De
10 min read
Component Based Diagram - Unified Modeling Language (UML)
Component-based diagrams are essential tools in software engineering, providing a visual representation of a system's structure by showcasing its various components and their interactions. These diagrams simplify complex systems, making it easier for developers to design, understand, and communicate the architecture. By breaking down a system into
9 min read
Profile Diagram - Unified Modeling Language(UML)
Unified Modeling Language (UML) is a standardized modeling language that provides a variety of diagram types to describe software systems. One of the more specialized types of diagrams is the Profile Diagram. This article will help to understand what Profile Diagrams are, their importance, components, and practical steps to create them, along with
7 min read
Communication Diagram - Unified Modeling Language(UML)
A Communication Diagram in Unified Modeling Language (UML) visually represents the interactions between objects or components in a system. It focuses on how messages are exchanged between these elements, highlighting the flow of information in a sequence. By illustrating both the structural and behavioral aspects of a system, communication diagrams
7 min read
Class Diagram | Unified Modeling Language (UML)
Class diagrams are a type of UML (Unified Modeling Language) diagram used in software engineering to visually represent the structure and relationships of classes in a system. UML is a standardized modeling language that helps in designing and documenting software systems. They are an integral part of the software development process, helping in bo
13 min read
Which UML Diagrams are mostly used?
The UML diagrams that are most commonly used are Class Diagrams, Sequence Diagrams, and Use Case Diagrams. These diagrams are essential in software development for visualizing and communicating different aspects of a system's design and behavior. Class diagrams provide a foundational view of the system's structure, showing the classes in the system
2 min read
Tools for Designing and Drawing UML Diagrams
Discovering the right tools for designing UML diagrams is essential for efficient software development. This article explores various software options tailored to meet diverse project needs, emphasizing functionality, usability, cost, customization, and community support. Important Tools for Designing and Drawing UML Diagrams What is UML?Criteria f
6 min read
Difference between Structural Diagrams and Behavioral Diagrams
Structural and behavioral diagrams are two types of diagrams used in UML (Unified Modeling Language) to represent different aspects of a system. While both types of diagrams are used to model different aspects of a system, they serve different purposes and focus on different aspects of the system. What are Structural Diagrams?Structural diagrams in
2 min read
Differences between Composite Structure Diagrams and Component Diagrams
Two important types of diagrams used in this process of designing software systems are Composite Structure Diagrams and Component Diagrams. They are the types of Structural Diagrams. While they both help visualize how different parts of a system work together, they focus on different aspects of the system. What are Composite Structure Diagrams?We u
2 min read
Handling State and State Management | System Design
State management is a critical aspect of system design that involves managing the state or condition of a system at any given point in time. In software development, state refers to the current values of variables, data, and configurations that determine the behavior of an application or system. Effective state management is essential for ensuring
12 min read
Unified Process in OOAD
The Unified Process (UP) in Object-Oriented Analysis and Design (OOAD) is a flexible and iterative approach to developing software. It focuses on creating working software increments, collaborating with team members, and adapting to changes. Important Topics for Unified Process in OOAD What is Unified Process?Importance of Unified ProcessKey Princi
9 min read
Twine - A Unified Cluster Management System for Shared Infrastructure
Twine - A Unified Cluster Management System for Shared Infrastructure introduces Twine, is a system designed to manage and coordinate resources across different computing clusters efficiently. Twine aims to improve resource utilization, simplify management tasks, and support a variety of applications within shared infrastructure environments. It pr
11 min read
Sequence Diagram (UML) of Ecommerce Firm in Software Engineering
Sequence Diagrams for an E-commerce Firm can be broken into 5 main functionalities: Sign Up FunctionalityLogin FunctionalityAdd to Cart FunctionalityProduct Order FunctionalityCustomer Care Functionality Let us see about these functionalities UML or Sequence diagrams one by one: 1. Sign-up Functionality UML (Sequence Diagram) in E-Commerce Firm: He
2 min read
UML Digital Forensic Model
Unified Modeling Language (UML) contains a set of rules for modeling software and system designs. It is used to model various processes of digital forensics. The digital forensic process of UML consists of five main phases: 1. Collection PhaseDigital evidence is collected from various sources such as computers, smartphones, and other digital device
2 min read
Project Idea | (Online UML Designing Tool)
The project is based on web-based UML designing. The main reason for selecting this topic was that now a day there is boom of internet users who wants to complete their work in less time and more efficient manner. The main objective of this tool is to provide a good quality online tool with the help of which one can draw  UML designs in optimal tim
3 min read
Timetable Generating System UML diagram
Unified Modeling Language (UML) is a standardized modeling language widely used in software engineering for visualizing, specifying, constructing, and documenting the artifacts of a system. UML provides a set of graphical notations and a framework for modeling complex systems, helping software developers and system architects communicate and unders
13 min read
UML Full Form
The full form of UML is "Unified Modeling Language". It is a general-purpose modeling language. The main aim of UML is to define a standard way to visualize how a system has been designed. It is quite similar to blueprints used in other fields of engineering. UML is not a programming language, it is rather a visual language. We use UML diagrams to
3 min read
What are the advantages and disadvantages of UML?
Unified Modeling Language (UML) is like a blueprint for software developers. It helps them plan and design complex systems by creating diagrams that show how different parts of the system will work together. We'll look at the advantages and disadvantages of UML. Understanding these can help developers use UML effectively and avoid its pitfalls, mak
2 min read
Is UML part of SDLC?
Yes, UML (Unified Modeling Language) is often used as part of the Software Development Life Cycle (SDLC). UML provides a standardized way to visualize the design of a system before it is implemented, making it easier for stakeholders to understand the system's architecture, design, and behavior. Unified Modeling Language (UML) is used in various ph
2 min read