A branch represents a transition branching and/or connection point. Using branches you can create a transition that has more than one destination state, as well as several transitions that merge together to perform a common action.
When control passes a branch, its action is executed, and then the guards of transitions exiting the branch are evaluated. The first enabled transition – i.e., the transition whose guard evaluates to true – is taken.
Control never stays in a branch state; it always passes through. Therefore, triggers cannot be specified for transitions exiting branches. When control passes a branch, branch’s action is executed.
Demo model: Transition with Branches Tests Numbers
To draw a branch state
Name – The name of the branch state. The name is used to identify the state within the statechart.
Ignore – If selected, the branch state is excluded from the model.
Show name – If selected, the name of the branch state is displayed on a presentation diagram.
Action – Here you can write Java code to be executed when the statechart enters the branch state.
A branch may have at most one special outgoing transition marked default branch exit. This transition is taken in case all other outgoing transitions are closed.
Transitions exiting branch states have properties, slightly different from other transitions properties:
Conditional – If selected, this transition will be taken when the specified boolean Condition is true.
Default (is taken if all other conditions are false) – If selected, the transition is the default branch exit and will be taken if conditions defined for all other transitions exiting the branch state are false. If all outgoing transitions are closed and there is no default exit from a branch, a runtime error is issued.
Please note that transitions exiting branches do not have Guard conditions.
Statechart declaration rules
Statechart execution order