How to Draw State Machine Diagram

A simple guide to drawing your first state diagram — with examples

This post was originally published on June 12, 2019, and updated nigh recently on September 14, 2020.

Land diagrams are one of those things that seem intimidating at first, but in one case you start using them, you'll wonder how you e'er did without. Simply before we become into the diagramming part, starting time nosotros need to understand what a state machine is.

A land car is a device that stores the status of an object at whatsoever given fourth dimension. It can simulate sequential logic, likewise as model problems in various fields, including AI, maths, linguistics, and game evolution. A state machine can also change the object's condition or cause other deportment based on its input.

If you want to sympathize all the possible states and show how an object gets to and from each land, you'll want to visualize it. Hence, the state diagram.

What is a country diagram?

A state diagram is a graphic representation of a state automobile. Information technology shows a behavioral model consisting of states, transitions, and actions, also as the events that bear on these. It's also i of the 14 Unified Modeling Languages (UML) used for specifying, visualizing, constructing, and documenting software systems.

state_machine_diagram_template State machine diagram template bachelor in Cacoo

What's the difference between a state diagram and a flowchart? Well, despite having a clearly divers beginning and end betoken, state diagrams aren't useful for showing a progression of events because they depict transitions. And so they're better for showing shifts in behavior.

A flowchart shows the processes that change the state of an object. A land diagram shows the actual changes in state, not the processes or commands that created those modify.

How can a state diagram assistance y'all?

Information technology's useful for showing the progress of issue-driven objects in a reactive system, such as an ATM. First, the machine is either on or out of lodge. When the card's inserted, the user enters their pin. If it'southward correct, they're taken to another set up of options. If wrong, the process is ended.

Land diagrams are also useful for describing how an object moves through various states inside its lifetime. For instance, the motion of an academic through their career: they begin equally a freshman, then move to sophomore, inferior, and so senior.

How to depict a state diagram

Each diagram commonly begins with a dark circle that represents the initial state and ends with a bordered circle that represents the final land. States are denoted with rectangles with rounded corners. Each rectangle is labeled with the name of the state. And transitions are marked with arrows that link one country to another, showing how the states change. Y'all'll find a run through of the virtually pop symbols below.

Composite state (also known as a 'nested state')

This refers to a land that encompasses various sub-states, which are nested into it. Sub-states are used to simplify complex flat land diagrams past showing that some states are only possible inside a particular context. In the air toaster oven example beneath, the 'heating' status of the machine represents the composite/nested state.

UML_state_machine_Fig5 Toaster oven land machine with entry and exit deportment

Choice pseudostate

This is represented past a diamond shape on the diagram. It indicates a dynamic status that has several potential results.

660px-UML_state_machine_Fig2 An extended state machine of "inexpensive keyboard" with extended state variable key_count and various guard conditions

Trigger

This is a message that moves an object from state to state. In the keyboard instance below, pressing CapsLock is the triggering event. If the keyboard is in the "default" land, pressing CapsLock will crusade the keyboard to enter the "caps_locked" land. However, if the keyboard is in the "caps_locked" state, pressing CapsLock will cause the keyboard to enter the "default" state.

660px-UML_state_machine_Fig1 UML state diagram representing the computer keyboard state auto

Consequence or Transition

This is when a moment triggers a shift. These are represented by labeled transition arrows. In the example above, pressing CapsLock is the outcome that triggers the 'default' and 'caps_locked' states.

Initial State

This represents the first state in the process. Information technology appears as a dark circumvolve with an arrow leading from information technology.

⚫→

Final Country (or terminator land)

This represents the object's terminal state. Information technology appears as an pointer pointing to a filled circumvolve nested inside another circle.

exit point
Go out betoken

A circle with an X through information technology represents the indicate at which an object escapes the country machine. The exit point is used when the procedure is interrupted or left incomplete due to an error or issue.

Exit point

Baby-sit

This is a boolean condition that must exist truthful for a state transition to occur. If the condition is false, the transition does not occur. Information technology'due south written in a higher place the transition arrow.

State

States stand for the current status of an object and appear as a rounded rectangle. In the example below, 'Closed', 'Open', and 'Deleted' are all states.

StatePattern_Statechart

State transition diagrams

This refers to when the object transitions from 1 land to some other, the events that must accept taken place earlier the transition can occur, and the activities during the life of the object.

Substate

This refers to a land contained inside a composite state'due south region. In the toaster oven example above, 'toasting' and 'baking' are sub-states in the larger 'heating' composite state.

Land diagram examples

Source: uml-diagrams.org

Source: lucidchart.com

Last thoughts

State diagrams are an essential tool for visualizing system behavior. Setting this data out in a diagram means you can see an object'south behavior throughout its entire lifespan, besides as the different events that cause various transitions, at a glance.

Pick out your dedicated diagramming software — ideally one that has a robust library of UML templates and shapes — and begin making your beginning state diagram today. If you're working with a team, make sure y'all invest in software that lets yous work collaboratively with your team in existent-fourth dimension, so you can edit diagrams together, hands share with others, and get feedback correct on your canvas.

Georgina Guthrie Georgina is a displaced Brit currently working in French republic as a freelance copywriter. Before moving to sunnier climates, she worked as a B2B agency author in Bristol, England, which is too where she was born. In her spare time, she enjoys old films and cooking (badly).

How to Draw State Machine Diagram

Source: https://cacoo.com/blog/a-simple-guide-to-drawing-your-first-state-diagram-with-examples/

0 Response to "How to Draw State Machine Diagram"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel