0% found this document useful (0 votes)
163 views11 pages

5 Steps To Draw A State Machine Diagram

This document provides a 5-step tutorial for drawing a state machine diagram in UML: 1. Define the states of the subject (e.g. bank account with/without funds) and draw them on the diagram. 2. Add descriptions to explain each state. 3. Draw transitions between states to depict relationships. 4. Define trigger events for the transitions (e.g. deposit, withdraw). 5. Add guard conditions to transitions to impose constraints on when they can fire (e.g. balance must be > 0 to withdraw).

Uploaded by

SudeepSah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views11 pages

5 Steps To Draw A State Machine Diagram

This document provides a 5-step tutorial for drawing a state machine diagram in UML: 1. Define the states of the subject (e.g. bank account with/without funds) and draw them on the diagram. 2. Add descriptions to explain each state. 3. Draw transitions between states to depict relationships. 4. Define trigger events for the transitions (e.g. deposit, withdraw). 5. Add guard conditions to transitions to impose constraints on when they can fire (e.g. balance must be > 0 to withdraw).

Uploaded by

SudeepSah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Tutorial 5 Steps to Draw a State Machine Diagram

5 Steps to Draw a State Machine Diagram


This tutorial will show you how to draw a simple state machine diagram in 5 steps, using Visual Paradigm. We are
going to walk through an example which models the behavior of a bank account, following the Unified Modeling
Language (UML) as shown below.

Step 1 Define States


Generally speaking, a state in UML is a condition or situation an object (in a system) might find itself in during its
life time. We capture the behavior of the subject object through modeling these various states and transitions
between them.

In order for others to understand them more easily, abstraction also takes place for simplicity reason in the modeling
process. So it is important to note that a state machine diagram does not necessarily model all possible states, but
rather the critical ones only. When we say critical states, we mean those that act as stimuli and prompt for
response in the external world.

Take our bank account example above. As far as the behavior goes, there really isnt significant difference when the
balance is $1,000 or $1,001. However, the state becomes much more meaningful when the balance hits zero.

1. Select Diagram > New from the toolbar.

2. In the New Diagram window, select State Machine Diagram and click Next.

Page 1 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

3. Enter Bank Account as diagram name and click OK to create the diagram.

The new diagram appears with an initial state (a solid black circle) by default.

4. Drag State from the toolbar onto the diagram. Name it account with funds.

5. Again, drag State from the toolbar onto the diagram. Name it zero balance.

Step 2 Describe States


After drawing states in the diagram, you probably want to elaborate what the states are about for others to
understand a little better. To do that, we can choose to add documentation to those states.

1. Click on Show Description on the right of the statusbar.

Page 2 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

2. Drag the title bar of Description pane and move it next to the state account with funds. Select account with
funds and enter the description: When the balance of the bank account exceeds $0.

3. Select the zero balance state. Enter its description: When the balance of the bank account hits $0.

Step 3 Draw Transitions


Now that weve finished drawing the states, lets turn our attention to describing the relationships between them. To
depict a transition between two states, we draw a directed line from the source to the target state.

1. Move your mouse pointer over the initial state shape.

2. Press on the Resource Catalog button that appears above the shape. Drag to the state account with funds.

Page 3 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

3. Release the mouse button over account with funds. A transition will be created.

4. Similarly, create a transition from the state account with funds to zero balance. This time, move your
mouse pointer over account with funds, then press on and drag the Resource Catalog button and release
your mouse on the state zero balance.

5. Apply the same technique to create a transition from state zero balance to account with funds.
After drawing it, press on the transition connector and drag to the left to make a cup handle shape as shown
below.

6. Create the final state. This time, move your mouse pointer over the state zero balance. Then, press on the
Resource Catalog button and drag to the empty region below the state.

Page 4 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

7. Release the mouse button. In the popup pane, select Transit -> Final State.

This creates a final state.

8. Click a self-transition on the state account with funds. Move your mouse pointer over the state account with
funds and click on the Resource Catalog button.

9. Select Self Transition -> State in the popup pane.

Page 5 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

10. Move the transition to the left as shown below.

11. Add another self-transition on account with funds. Rearrange the line as needed. After drawing all
transitions, you should end up with a similar diagram as shown below.

Step 4 Define Transition Triggers


A transition from one state to another takes place when the designated trigger event fires. A trigger event can be an
event from the external world or simply a users interaction.

1. Right click on the transition that connects the initial state and account with funds and select Open
Specification from the popup menu.

Page 6 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

2. Open the Triggers tab.

3. Click Add and then select Call Trigger from the popup menu.

4. In the Call Trigger Specification, enter open bank account as name and click OK.

5. Click OK again in the Transition Specification to return to the diagram. You should see the trigger name
appear as the caption transition.

6. Continue to enter the remaining trigger events as shown below.

Page 7 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

Step 5 Define Guard Conditions


Sometimes a transition would not be appropriate, although the same trigger event fires. For example, lets just say
that someone can withdraw funds only when there are sufficient funds available in the account. So it would be good
for us to impose a constraint to check against that before allowing the transition happen. In UML, this constraint is
called a guard condition. Lets continue with our example.

1. Right-click on the self-transition withdraw funds and select Open Specification from the popup menu.

2. In the General tab of the Transition Specification, enter balance > 0 as Guard and click OK to confirm.

Page 8 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

You can see the transition caption updated with guard presented.

3. Apply the same technique to add the balance == 0 as guard condition of that connects the state account
with funds and zero balance as shown.

Additional Examples of State Machine Diagrams

Page 9 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

Page 10 of 11
Tutorial 5 Steps to Draw a State Machine Diagram

Return to Visual Paradigms Website

Page 11 of 11

You might also like