Prev | Next |
Introducing StateMachine Diagrams
The StateMachine diagram is one of the nine core SysML diagram types; it is used to create and visualize the behavior of Blocks as they change states. The key elements on the diagram are States, Transitions and Pseudostates. The States represent the significant time in the lifetime of the Block from a particular perspective, the Transitions represent the movement from one State to another and the Pseudostates, as we will see, act as traffic controllers that influence the way that transitions work.
Enterprise Architect helps a modeler to create any number of StateMachine diagrams, and each diagram can have any number of States, Transitions and Pseudostates. Each of these diagram elements and connectors can in turn have other information added that will embellish the diagrams with more detail. The application has a pattern library productivity tool that is very useful for newcomers and welcome equally to experience modelers. This screen capture shows the list of model patterns that can be used to create StateMachine diagrams.

The pattern can be used to create a number of different StateMachines; in this example we create a simple (single region) diagram that has all the appropriate detail added to the States and the Transitions. A modeler can create this diagram in the appropriate location in the repository and then edit the States and Transitions and diagram to make it suit their own modeling context. The initial StateMachine diagram created from the pattern will resemble this:
This handy feature prompts engineers to complete details such as the Trigger and Guard conditions on a Transition, or the Entry and Exit actions on a State, that they might not otherwise have been aware of - the result being diagrams that are aligned with best engineering practice, producing better outcomes for customers.
Creating StateMachine Diagrams
A StateMachine diagram can be created from a number of places in the User Interface by using the:
- Design ribbon - 'Add Diagram' Icon on the 'Diagram' panel
- Browser window toolbar - 'New Diagram' icon
- Browser window context menu - 'Add Diagram' option
We will use the Design ribbon to create a StateMachine diagram. Firstly you select the location in the Browser window where you want the StateMachine diagram to be located. As with all diagrams, this can be either a Package or an element, but it is common to insert StateMachine diagrams into an element such as a Block to describe the important phases in a Block's lifetime. Once the location has been selected in the Browser window then select:
Ribbon: Design > Diagram > Add Diagram

Selecting this option will open the New Diagram dialog, allowing you to name the diagram; the name will default to the name of the Package or element that contains the diagram, but you can change it. With the SysML perspective chosen and the version of SysML selected, a list of diagrams will be displayed from which you can select the StateMachine diagram. Once the Diagram Toolbox, which contain the elements and relationships defined by the SysML specification to be applicable for constructing StateMachine diagrams. Any number of other Toolbox pages can be opened if required, in addition to the Common (Elements) and Common Relationships pages that are always available.
is selected a new StateMachine diagram will be created in the location selected in the Browser. The diagram canvas will be opened, allowing you to start adding elements and connectors that describe the important phases in the lifetime of the subject. Enterprise Architect will also display the StateMachine pages of the
The most important elements and connectors used with the StateMachine diagram are:
Elements
- State - defines a significant phase in an entity's lifetime
- StateMachine - defines a set of States
- Initial - defines the entry point to a Region
- Final - defines the last State an entity will have
- History - acts a memento or bookmark when a State is exited and re-entered
Connectors
- Transition - represents the movement from one State to another

Elements can be added to the diagram by dragging-and-dropping them from the Toolbox pages onto the diagram canvas. It is considered good practice to start with an Initial and one or more Final State elements, which should be named appropriately to describe the way the StateMachine starts and the potentially multiple ways it might finish. Leaving the name blank or giving it a name that is hackneyed such as 'starts' or 'end' will not help to make it clear to the reader what system or part of a system is being modeled, and can lead to misinterpretation of the diagram. With these nodes added and appropriately placed in the diagram, States and Transitions can be added, thus defining the important phases in the lifetime of the entity being modeled.
Once a basic diagram has been created, and as knowledge of the domain and the system's behaviors is further developed, it is possible to add Triggers, Events and Guards to the Transitions, and Entry, Do and Exit behaviors to the States. The newcomer can often perceive these diagrams to be trivial, but they can reveal profound insights that would not otherwise be possible to see.