2

I have referred quite a lot of materials online, I saw the usage of merge and junction is almost the same? Some sites said to use the diamond shape as a merge, some said to use junction. Can I know which one is correct? The following images are the material I have read.

merge using diamond shape merge using diamond shape

merge using junction merge using junction

Christophe
  • 68,716
  • 7
  • 72
  • 138
Sam
  • 19
  • 5
  • 1
    The first is about activities and the second is about states. You can not compare them. – qwerty_so Jul 08 '22 at 08:25
  • so you meant about is state diagram will be using the junction to merge, and activity diagram use the diamond shape to merge? – Sam Jul 08 '22 at 08:42
  • Yes, that's it. Do not confuse both diagram types (and their elements). They are partially similar, but have totally different meaning. – qwerty_so Jul 08 '22 at 08:48
  • Okay totally understood, thanks for pointing it out! – Sam Jul 08 '22 at 09:04

2 Answers2

4

In a state machine diagram there are two pseudo states that are often confused: The junction state (a black filled circle) and the choice state (a hollow diamond). Don't confuse them with similar shapes in an activity diagram (initial node, decision node and merge node). They only look the same.

Now for the difference between choice and junction states: A compound transition fires, when its triggering event occurs AND all guards before an eventual choice state evaluate to true. Then all the effect behaviors up to the choice state are executed before any of the guards of outgoing transitions are checked. This allows dynamic branching depending on some value that only gets evaluated when the transition has fired.

A junction state just connects transitions. It could be replaced with as many transitions as there are possible routings. Such a transition only fires if all guards on the route evaluate to true.

Both states can have as many in- and outgoing transitions as you like.

Axel Scheithauer
  • 2,758
  • 5
  • 13
  • Actually I was not aware that there is a diamond shaped choice in state diagrams. One never stops learning. (I'm not using state diagrams too often anyway.) – qwerty_so Jul 08 '22 at 20:03
0

As a side note (too long for a comment) the notation for the combined merge/decision needs some clarification. UML 2.5 states on p. 387:

15.3.3.5 Merge Nodes

A MergeNode is a control node that brings together multiple flows without synchronization. A MergeNode shall have exactly one outgoing ActivityEdge but may have multiple incoming ActivityEdges.

and below (a bit more obscure!):

15.3.3.6 Decision Nodes

A DecisionNode is a ControlNode that chooses between outgoing flows. A DecisionNode shall have at least one and at most two incoming ActivityEdges, and at least one outgoing ActivityEdge. If it has two incoming edges, then one shall be identified as the decisionInputFlow, the other being called the primary incoming edge. If the DecisionNode has only one incoming edge, then it is the primary incoming edge.

Note that this is about activities and not states!

As @AxelScheithauer noted, the diagram rendering may deviate. P. 390 of UML 2.5 states

The functionality of a MergeNode and a DecisionNode can be combined by using the same node symbol, as shown in Figure 15.34. At most one of the incoming flows may be annotated as a decisionInputFlow. This notation maps to a model containing a MergeNode with all the incoming edges shown in the diagram and one outgoing edge to a DecisionNode that has all the outgoing edges shown in the diagram.

enter image description here

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • 1
    It is correct, that the metamodel doesn't contain a mixed node. However, the notation does: _UML 2.5.1: The functionality of a MergeNode and a DecisionNode can be combined by using the same node symbol, as shown in Figure 15.34. At most one of the incoming flows may be annotated as a decisionInputFlow. This notation maps to a model containing a MergeNode with all the incoming edges shown in the diagram and one outgoing edge to a DecisionNode that has all the outgoing edges shown in the diagram._ – Axel Scheithauer Jul 09 '22 at 07:13
  • @AxelScheithauer I was pretty sure that there was such a paragraph. But I did not find it on the fly. I will update the "comment-answer". It's strange in any case... – qwerty_so Jul 09 '22 at 07:51