How To Draw A State Diagram
This mail was originally published on June 12, 2022, and updated most recently on September 14, 2022.
Country diagrams are ane of those things that seem intimidating at kickoff, just once yous start using them, you'll wonder how you always did without. But before we get into the diagramming part, first we demand to sympathize what a state machine is.
A country machine is a device that stores the status of an object at any given time. Information technology can simulate sequential logic, as well as model problems in various fields, including AI, maths, linguistics, and game development. A state machine tin can also modify the object's condition or crusade other actions based on its input.
If y'all want to empathise all the possible states and prove how an object gets to and from each state, you'll desire to visualize information technology. Hence, the state diagram.
What is a land diagram?
A country diagram is a graphic representation of a state machine. It shows a behavioral model consisting of states, transitions, and actions, as well equally the events that affect these. It'southward also i of the 14 Unified Modeling Languages (UML) used for specifying, visualizing, constructing, and documenting software systems.
State machine diagram template bachelor in Cacoo
What's the difference betwixt a state diagram and a flowchart? Well, despite having a clearly defined start and stop point, state diagrams aren't useful for showing a progression of events considering they draw transitions. And then they're amend 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 change.
How can a state diagram aid you lot?
It'southward useful for showing the progress of event-driven objects in a reactive arrangement, such equally an ATM. Get-go, the machine is either on or out of order. When the card'southward inserted, the user enters their pin. If information technology's correct, they're taken to another set of options. If incorrect, the procedure is concluded.
Country diagrams are also useful for describing how an object moves through various states within its lifetime. For example, the movement of an academic through their career: they begin as a freshman, and so move to sophomore, junior, and and then senior.
How to draw a state diagram
Each diagram usually begins with a dark circle that represents the initial state and ends with a bordered circle that represents the concluding state. States are denoted with rectangles with rounded corners. Each rectangle is labeled with the name of the country. And transitions are marked with arrows that link one state to some other, showing how u.s. change. You'll find a run through of the well-nigh popular symbols below.
Composite state (also known as a 'nested land')
This refers to a land that encompasses various sub-states, which are nested into it. Sub-states are used to simplify complex flat state diagrams by showing that some states are only possible inside a particular context. In the air toaster oven example beneath, the 'heating' status of the car represents the composite/nested land.
Toaster oven land auto with entry and leave actions
Choice pseudostate
This is represented past a diamond shape on the diagram. It indicates a dynamic condition that has several potential results.
An extended state car of "cheap keyboard" with extended country variable key_count and various guard conditions
Trigger
This is a message that moves an object from country to state. In the keyboard example below, pressing CapsLock is the triggering result. If the keyboard is in the "default" land, pressing CapsLock volition cause the keyboard to enter the "caps_locked" country. Even so, if the keyboard is in the "caps_locked" state, pressing CapsLock will cause the keyboard to enter the "default" state.
UML state diagram representing the figurer keyboard state machine
Event 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 starting time country in the process. It appears equally a night circle with an pointer leading from it.
⚫→
Final State (or terminator state)
This represents the object'due south final state. It appears as an arrow pointing to a filled circle nested inside another circle.
←
Get out point
A circumvolve with an X through it represents the bespeak at which an object escapes the state machine. The exit point is used when the process is interrupted or left incomplete due to an fault or consequence.
Guard
This is a boolean condition that must be true for a land transition to occur. If the status is imitation, the transition does non occur. Information technology's written above the transition pointer.
State
States represent the current condition of an object and appear every bit a rounded rectangle. In the example below, 'Closed', 'Open', and 'Deleted' are all states.
State transition diagrams
This refers to when the object transitions from one state to another, the events that must have taken place before the transition tin occur, and the activities during the life of the object.
Substate
This refers to a state contained within a blended land's region. In the toaster oven example above, 'toasting' and 'blistering' are sub-states in the larger 'heating' composite land.
State diagram examples
Source: uml-diagrams.org
Source: lucidchart.com
Final thoughts
State diagrams are an essential tool for visualizing arrangement beliefs. Setting this information out in a diagram means you can see an object'due south behavior throughout its entire lifespan, every bit well as the different events that cause various transitions, at a glance.
Pick out your dedicated diagramming software — ideally 1 that has a robust library of UML templates and shapes — and begin making your first country diagram today. If you're working with a team, make sure you invest in software that lets you piece of work collaboratively with your squad in real-time, so you tin edit diagrams together, easily share with others, and get feedback correct on your canvas.
Collaborate on ideas to align your team's vision in Cacoo
Source: https://cacoo.com/blog/a-simple-guide-to-drawing-your-first-state-diagram-with-examples/
Posted by: parkblegame94.blogspot.com

0 Response to "How To Draw A State Diagram"
Post a Comment