4

In State Machine diagrams, in some online resources, the condition is merely drawn on the arrow (the left figure below) and in others similar to right figure, where a choice node is specifically used.

Which one of the following is correct UML?

6
  • 1
    I didn’t downvote but IMHO those kind of questions are missing the point. SW Engineering is not about correct syntax of diagrams (the tool checks that for you) but to find proper names and meaning of the states. Nov 13, 2021 at 8:06
  • 1
    Either could feasibly be used, although I personally apprehended the meaning of the diagram on the right much more quickly than that on the left. The reason the diagram on the left was harder to parse, besides the different and less suggestive spatial arrangement of elements, is because I had to search multiple paths and read the associated text before I could infer that a decision based on a parameter was involved.
    – Steve
    Nov 13, 2021 at 8:07
  • 1
    @HartmutBraun: Come on, there is nothing wrong in trying to use correct UML syntax when drawing state diagrams, that could make communication between software engineers less ambigous, There is also nothing wrong in asking such a question here on this site, UML questions are perfectly on-topic here. And about tools: most diagram tools I have seen don't do any syntax or semantical checks, or at least they are not very restrictive. Some years ago, I abused use case digrams in a popular comercial CASE tool for drawing data flow digrams, for example.
    – Doc Brown
    Nov 13, 2021 at 9:48
  • 3
    @HartmutBraun diagrams are used for communication. diagrams following conventions are easier to understand than diagrams that follow their own rules. So I do think there is a point in getting diagrams "right".
    – Helena
    Nov 13, 2021 at 10:32
  • @Helena Yes and No. It’s about communication, agreed. But conventions do not always get you there. In particular, getting it right is not a matter of “which one is correct UML”. Correct is what is easy to comprehend, preferably without prior knowledge of the syntax that is used. If the syntax carries this aspect: great! But often I find people being caught in conventions without seeing the real SW engineering problem: what is the meaning of words within the boxes and diamonds and circles. If this question is about passing an UML test I’d say: they are teaching the wrong stuff. Nov 14, 2021 at 9:09

1 Answer 1

4

As there are no triggers defined for the transitions, only guards, they are completion transitions, meaning that once a state finishes its actions, a completion event will be generated to leave the source state if a valid transition can be found.

As you frame the question "Using Choice Node...", the diamond represents a dynamic conditional branch, meaning that the guards of the outbound transitions will only be checked after the transition in.

Therefore, in the case where Value equals 8, the version on the right would result in an invalid state, as you would leave State A on completion, entering the choice pseudo state, but not be able to enter either State B or State C as neither guard evaluate true. Whereas the version on the left would not leave State A.

So to answer your question, they are both "correct UML", but they are not equivalent.

See "14.2.3.8.3 Completion Transitions and completion events" in https://www.omg.org/spec/UML/2.5.1/PDF most of what you need for this question is there.

2
  • Thanks, just a follow up question. If an arrow from state A to state B does not have a label (no event, guard or action) does that mean as soon as any do/activity is complete in A, the system automatically shifts to B?
    – user17302
    Nov 19, 2021 at 17:13
  • 1
    Yes, a transition with not explicit trigger will implicitly trigger on a completion event which is generated by the completion of activity in state A.
    – Mesmo
    Nov 20, 2021 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.