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.
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.
Statechart diagrams generally contain:
States: represent the states of the object during its lifetime
Transitions: directed link-lines representing the transitions between object states, and the events that trigger transitions.
Together's Statechart diagrams can also show:
Start/end state
History state
Fork/Join to represent multiple transition sources or targets
Self-transition means that the flow leaves the State, dispatching any exit Action(s), then re-enters the State, dispatching any entry Action(s).
Select the desired State on the diagram.
Drag a Transition link from the selected state and
drop it on the diagram background.
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.
Internal transition is a shorthand for handling events without leaving a State and dispatching it's exit/entry Actions.
Select the desired State on the diagram
From its speedmenu choose New Internal Transition.
You can immediately edit the event name in place. For additional information see Entry/Exit Actions below.
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.
Create an internal transition in
the desired State.
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.
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:
You may want to resize the main State larger. You can essentially draw another Statechart diagram inside it, complete with Start/End/History states and transitions of all kinds, to create, in effect, a substate diagram
You can nest multiple levels of substates inside one State. For really complex substate modeling, however, you may find it easier to create different diagrams, model each of the substate levels individually, and hyperlink the diagrams sequentially.
Specify the event name in the event
property of the Transition.
Optionally specify any arguments in the event arguments property.
Enter an appropriate expression in the condition property of the Transition.
Enter an appropriate value in the action property of the Transition.
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:
Identify the States involved. If necessary, place all the States on the diagram first, and lay them out as desired.
Place either a horizontal or vertical Fork/Join on the diagram. Resize it as needed.
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.
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.
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 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.
You can easily reuse any elements that you have already created in other Statechart diagrams. Invoke Add Existing command on the diagram's context menu and navigate in the dialog's Explorer to the existing Statechart diagram and select one or a number of its elements, States, Histories, and/or SyncBars (Fork/Joins).
Using the Clone command on the context menu of the diagram's Explorer node, you can quickly create a new diagram with the same content as the existing one. The new diagram has a unique name and is created in the same package.
The above can be useful if modeling complex composite states or substates.
You can find detailed information on UML modeling techniques for Statechart diagrams in Chapter 21 of the UML User's Guide.