break / stop execution in UML sequence diagram mid-way inside alt / opt
Asked Answered
F

3

11

In a UML Sequence Diagram - If a flow should stop if a condition is met midway, how would it be best represented with alternate / optional fragments?

i.e. - If the stop condition is not met then the flow is continued for several more steps. Should the alternate fragment cover all of the steps since the stop condition, making all steps past it part of the alternate fragment, or is there a notation to handle the stop inside a small alternate fragment (confined only to the condition)?

Farias answered 10/7, 2016 at 14:37 Comment(0)
D
17

There are three options for this situation. Each of them I illustrate with a diagram showing how the respective combined fragment should be used. The actual behaviour is hidden with interaction references (normalFlow for a flow that should normally be executed and breakFlow for any flow that should happen in case of a required break).

The first solution is the most convenient one - it exactly covers your case and you can also use the positive version of a break guard. However each of them provide you a valid possibility.

  1. Break combined fragment

When a break combined fragment is met and its guard condition is true, only this fragment is still executed and then the execution of the interaction (flow) stops. If the condition is not met, the combined fragment is omitted and the normal flow continues. This is exactly the case you describe. In this case you would put the messages that shouldn't be executed in case of a break condition after the break combined fragment.

enter image description here

  1. Opt combined fragment

When an opt combined fragment is met it executes only if a guard condition is true. The rest of a flow continues regardless of the condition. You can put the part of the flow that is continued only if the break condition is not met inside the opt combined fragment. The opt fragment should have a guard that is opposite to the condition at which the flow should stop. If any additional actions should happen in case of a break, they should be put after the opt combined fragment.

enter image description here

  1. Alt combined fragment

When an alt combined fragment is met its guard conditions are evaluated and only the eventual one fragment which guard evaluates to true is executed. There might be also a situation when none of the guards evaluate to true and no fragment is executed in such case. Whatever flow is after the combined fragment is executed normally anyway. In this case you would preferably put two fragments, one with the correct operation guard and the second one with a condition that should cause a break. Put the normal flow in the first fragment and whatever should happen in case of a break in the second fragment.

enter image description here

Diplomatist answered 10/7, 2016 at 16:13 Comment(0)
F
4

You could shortcut the whole thing by using an opt fragment:

enter image description here

One could start arguing that this is syntactically incorrect, but it transports the message (I guess). And that is what counts.

From my personal experience: use fragments as few as possible. Rather split your scenarios to focus on the certain important aspects. A SD is a snapshot of the system at a place where you want an overview over what's going on and not a detailed roadmap with each possible cat and dog trail.

Familiar answered 10/7, 2016 at 15:22 Comment(2)
Comment about splitting the SD is helpful. It would make it more pure, although in my case it is better to have a break in the flow.Farias
The most important part of my answer is "it transports the message". As long as this is the case you are quite free in your stylistic elements.Familiar
B
1

In the accepted answer, options # 1 and # 3 are equivalent in behavior and correctly address the question, with option # 1 being justifiably being more elegant.

Option # 2, however, has a different behavior. breakFlow will be executed in addition to normalFlow if the continuation condition is true, and it should not. The only situation in which the behavior would technically be equivalent to the other two options is if breakFlow is empty.

I do not have the reputation points to add a comment to the answer.

Bowyer answered 24/2 at 20:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.