Search code examples
umlstatediagramstaruml

Is a state without a direct transition allowed in UML state diagram?


Is a state without a direct transition allowed in UML state diagram (SD) like the below drawn with StarUML?

State1 is not directly involved in any transition so I'm in doubt wether this is allowed in UML / desirable. I think in my application I'm actually modeling multiple objects in a single SD.

enter image description here


Solution

  • In short

    Based on the UML 2.5 specifications, this kind of diagram is perfectly valid. Nevertheless, by deduction, we can understand that it is not the best approach.

    The details : why it is valid

    According to the definitions (section 14.2.3.4.1):

    • State1 is a composite state made of exactly one region.
    • State2 and State3 are simple states, and in this case they are also direct substates of State1

    A first answer to your question is suggested by the rules on entering a state (section 14.2.3.4.5):

    Explicit entry: If the incoming Transition or its continuations terminate on a directly contained substate of the composite State, then that substate becomes active and ...

    This is also reinforced in the rules related to regions (section 14.2.3.2), and more precisely to their activation:

    • Either a region starts with its own local initial pseudo-event (that is automatically activated when the enclosing state is activated, or one its "orthogonal" regions (i.e. concurrent in the same composite state) is activated.
    • Or a region starts at an explicit state (substate) if the region is activated by an entering transition:

      an explicit activation occurs when a Region is entered by a Transition terminating on one of the Region’s contained Vertices.

    So your diagram is perfectly valid, with an explicit transition from initial state to the substate State2.

    The details: why it is not recommended

    First of all, it is suggested (section 14.2.4.5.1) that it may help in some case to hide the decomposition of a composite state:

    • With explicit activation, such hiding would require to draw a variation of the model, showing a transition from initial to State1 instead of the direct transition to State2.
    • With default activation, you'd have only one model: initial to State1 and State1::initial to State2. Up to you to show or hide the details. Or to zoom into the region ignoring its context.

    Then, if you'd later need to extend your composite state with multiple "orthogonal" regions:

    • with default activation, you'd just add additional regions with their own default activation.
    • with explicit activation, you'd have an asymmetry between one (explicitly activated) region, and the other regions (that require default activation).
    • alternatively, you could consider having multiple explicit activations. But this is not well supported: first there is no transition with multiple targets, second, multiple transitions from the (external) source state to the different (internal) target substates, would be ambiguous in regard of the semantics and execution model of transitions.

    The UML specs warn that if default activations are missing, one should consider the model as ill-defined, or that the region will never start. So it's safer to use a systematic approach, and always use default activation.