Statechart diagrams

Statechart diagrams enable you to model UML state machines. State machines are one of several ways to model the dynamics of a system or subsystem. They generally model the behavior of a single object as it goes through different states in response to events that occur during its lifetime, including its response to events. The state of an object is some situation during its life where it meets some condition(s), does something, or waits for an event.

Statechart diagrams emphasize the possible states of an object and the transitions between states. You can use them to model the lifetime of an instance of a class, an instance of a use case, or even an instance of a system. During that period, the object of interest can be exposed to different kinds of events to which it responds with some action, and the result of which is a change in the object's state.

Tip: To focus on the actions and activities of objects, use Activity diagrams.

Creating and drawing Statechart diagrams

If you need to learn how to create new diagrams in a project, or the techniques for placing elements and drawing links, consult the User's Guide topics found under " Working with Diagrams: Basic Diagram Techniques" in the Table of Contents. See Related Topics below.

Content

Statechart diagrams generally contain:

Together's Statechart diagrams can also show:

Working with Statechart diagrams

States


Transitions


Drawing a self-transition

Self-transition means that the flow leaves the State, dispatching any exit Action(s), then re-enters the State, dispatching any entry Action(s).

  1. Select the desired State on the diagram.

  2. Drag a Transition link from the selected state and drop it on the diagram background.

  3. In the Choose Destination dialog, navigate to the State where you began the link, select it, and click OK.

Tip: Another way is to draw a Transition between two States, and then drag the opposite end of the link line back to the desired State.

Creating internal transitions

Internal transition is a shorthand for handling events without leaving a State and dispatching it's exit/entry Actions.

  1. Select the desired State on the diagram

  2. From its speedmenu choose New Internal Transition.

You can immediately edit the event name in place. For additional information see Entry/Exit Actions below.

Specifying entry/exit Actions for a State

These are Actions executed upon entering or leaving a State, respectively. You create Entry and Exit Actions in Together Statechart diagrams as stereotyped internal transitions.

  1. Create an internal transition in the desired State.

  2. When you edit the name in place, use the following syntax:

Example: exit/setState(idle)

Optionally, you can create the internal transition and set the event, action, and arguments properties in the properties Inspector (speedmenu | Properties)u.

Creating nested substates

You can create a composite State by nesting one or more levels of States (i.e. substates) within one State. You can also place Start/End states and History states inside a State, and draw Transitions among the contained substates.

The easiest way to create a nested substate is to place a State node on the diagram background, drag it on top of another State, and drop it.

Tips:

Specifying an Event Trigger for Transitions


Specifying a Guard Condition for Transitions


Specifying an Action for Transitions


Showing multiple Transition sources or targets

A Transition may have multiple sources, meaning it is a join from several concurrent states, or it may have multiple targets, meaning it is a fork to several concurrent States.

You can show multiple transitions with either a vertical or horizontal orientation in your Statechart diagrams. The Statechart diagram toolbar provides separate Fork/Join buttons each orientation. The two orientations are semantically identical.

To create multiple Transitions:

  1. Identify the States involved. If necessary, place all the States on the diagram first, and lay them out as desired.

  2. Place either a horizontal or vertical Fork/Join on the diagram. Resize it as needed.

  3. If depicting multiple sources, draw Transitions from each of the source States to the Fork/Join; then draw a Transition from the fork/Join to the target State.

  4. If depicting multiple targets, draw a Transition from the source State to the Fork/Join; then draw Transitions from the Fork/Join to each of the target States.

Key elements and properties

Transitions

Most of the information for the Statechart diagram is communicated through the various properties of Transitions. With these you can specify event name and event arguments, conditions, action, and specify general and send/receive time constraints.

History State

History states enable modeling of objects that remember the last active substate of a composite state before leaving it. The deep property of a History State supports the UML deep history concept for multi-level nested substates: when checked it signifies that the object remembers the last active substate down to the innermost nested level.

Tips and Tricks


Related topics


Additional resources