Search code examples
umldiagramtransitionstate-machine

UML state machine diagram: triggered exit from a composite state


I have an UML state machine diagram, which looks like this:

    +-----------------------------------+
    | A                                 |
    |      +------+  E1   +------+      |  E2   +-----+
o-->|  o-->|  A1  |------>|  A2  |------------->|  B  |
    |      +------+       +------+      |       +-----+
    |                                   |
    +-----------------+-----------------+
                      | E3
                      V
                   +-----+
                   |  C  |
                   +-----+

In reality, composite state A has so many sub-states that I'd like to extract it into a separate diagram. This means that the transition arrow from A2 to B must be cut in half by an exit point.

But where should I put event E2? I think, I should put it on both sides of the exit point, that is, in both diagrams:

High-level diagram (the o-o is the decomposition icon, and (X) is the exit point):

    +-----------+
    |           |
    |           |   E2   +-----+
o-->|     A    (X)------>|  B  |
    |           |        +-----+
    |       o-o |
    +-----+-----+
          | E3
          V
       +-----+
       |  C  |
       +-----+

Low-level diagram:

+------------------------------------+
| A                                  |
|      +------+  E1   +------+  E2   |
|  o-->|  A1  |------>|  A2  |----->(X)
|      +------+       +------+       |
|                                    |
+------------------------------------+

Note that E2 is shown in both diagrams. Unfortunately, I cannot find anything in the UML spec to support this idea. On the contrary, this approach apparently causes a conflict (see section 14.2.3.9.3). But I think there is no conflict here:

  • Both transitions make the system leave state A and enter state B. So they practically form one transition.
  • Both diagrams are easy to understand because both show E2, and the exit point looks like a "gate" between the two diagrams, through which the system's state "moves" from (A, A2) to B. I think it would be confusing to show E2 only on one side of the exit point.
  • If there were another similar transition, for example from A1 to a state D (not shown), then it could be handled the same way, with a second exit point. However in that case the two exit points should be labeled differently (for example: "Exit from A1" and "Exit from A2").

Is this valid UML? If not, how should I solve this problem?


Solution

  • The event should be placed on the internal party of the transition only.

    Exit point is a pseudostate which essentially means it has no internal logic and as soon as the state machine reaches it, it "completes" meaning it is ready for the next transition. In your case you want the transition from A2 to be triggered when E2 occurs. That's why this event has to be placed on the internal part of a transition. On the other hand as soon as the transition reaches exit point (and it "completes") you want an uninterrupted further transition to B so no conditions should be placed on the outgoing (external) transition.

    Placing E2 on both "parts" of the transition will change the meaning of the diagram. It would stop transition on the exit pseudostate and wait until another E2 event occurs. Only then (after second E2 event) state machine will reach B state.

    Placing E2 on external part will also have a different meaning. The transition to exit point will occur only once the A2 completes (even if E2 occurs earlier) and only transition from exit point will wait for the E2 event. On the other hand the transition to the exit point happens as soon as A2 completes so if it happens any other possible transitions from A2 (e.g. some E4) will no longer be available since the state machine has already left A2 and waits on the exit point (for E2).

    You've actually answered your own question in the comments but I hope my word of explanation justifies the full answer.