donparalias
donparalias

Reputation: 1834

How to interpret a UML 2.5 State Machine diagram?

I am in need of identifying all the basic elements of a UML 2.5 State Machine Diagram. Unfortunately , there seems to be a lot of ambiguity on the notation of those diagrams, as there are a lot of different variations online.

My interpretation is that every state machine diagram , consists of a number of states and a number of transitions.

Every state has:

Every transition has:

My understanding of how the notation works can be summarized in Figure 1 (example of an electric door functionality following the notation [precondition] Event / [Transition Action]) and in Figure 2.

Example: When an event is triggered (e.g close button pressed), the precondition (if any) is evaluated (e.g is the doorway empty) and if the precondition is satisfied, a transition action (e.g close door) is triggered.

Figure 1 Electric Door State Machine

Figure 2 enter image description here

My questions:

  1. Is the Transition Action the realization of the transition or is simply an action that happens during the transition. In plain words, if the transition action/s go wrong, will the transition (new state) be successful? My question basically derives from the fact that a lot of sources suggest that instead of using a transition action, you can use an entry action when you arrive at the new state. In my understanding though a transition action is the realization of the transition and hence happens before entering the new state, in comparison to the entry action that happens immediately after arriving at the new state. So these are two completely different types of action in respect to the transition itself and time. It's crucial for me here to understand the timing of those actions.
  2. Is my general interpretation correct? (e.g. my understanding of what an event, post-condition and transition-action may be from Figure 1)

I know that there a dozen of variations of state machine diagrams, hence the different representations / interpretations but i am interested on the UML 2.5 one.

Upvotes: 2

Views: 1739

Answers (1)

qwerty_so
qwerty_so

Reputation: 36313

The Transition Action is what UML 2.5 states as association end of a transition:

effect : Behavior [0..1]{subsets Element::ownedElement} (opposite A_effect_transition::transition) Specifies an optional behavior to be performed when the Transition fires.

While the <<entry>> of a state is a behavior assigned to the state itself. That is, it will be triggered from where ever the transition comes from. In contrast the above effect is only trigger along the transition.

The effect can not "go wrong". What ever behavior is performed, is performed. No condition is checked here.

Whether a transition is triggered can be controlled by the [guard] which you wrongly named [precondition]. (One can start arguing, but you need to go with [guard].)

guard : Constraint [0..1]{subsets Namespace::ownedRule} (opposite A_guard_transition::transition) A guard is a Constraint that provides a fine-grained control over the firing of the Transition. The guard is evaluated when an Event occurrence is dispatched by the StateMachine. If the guard is true at that time, the Transition may be enabled, otherwise, it is disabled. Guards should be pure expressions without side effects. Guard expressions with side effects are ill formed.

With respect to timing you can think of a token traveling along the states. When the guard lets you pass, the <<exit>> behavior is performed. Then the transition's effect and finally the <<entry>> behavior of the next state.

Upvotes: 2

Related Questions