How to model optional actions on UML activity diagram

10,801

You're correct in the assumption that a fork will continue in all paths. To make an optional process simply use a Decision node (looks like a lozenge). From there you can proceed to your two optional actions or skip. Finally join the path again with the very same lozenge to merge the optional paths.

Basically it might look like this (not taking all the details of your activity into account):

enter image description here Just ignore all those fuzzy details about different actions. Atomic is enough for a start.

Share:
10,801
Michael Albers
Author by

Michael Albers

Updated on June 22, 2022

Comments

  • Michael Albers
    Michael Albers about 2 years

    After searching the net and a couple of old fashioned books I own, I still haven't found my answer to how to model an activity for a specific use case. I am fairly new to UML and thus activity diagrams.

    The activity is Add hotel. This is fictional, but the issue is exactly the same as my issue. My contract prevents me from talking about the real deal to third parties.

    In this activity the user provides necessary details and has two optional actions that he can choose at anytime while in the Add hotel activity:

    1. Add hotel chain
    2. Add loyalty program

    As said these are optional and not mandatory. The user is also able to proceed to save the entered data. However, when choosing one of these actions, I imagine another activity diagram should be invoked, named the same as the choice the user made. In this activity all relevant stuff is entered and at the endpoint the user returns to the Add a hotel activity after which the user has the option to choose the optional activities again or proceed to save the provided data.

    The only somewhat relevant answer I found was this one

    But as I understand it, a fork means all actions after it have to be carried out before the flow will continue after the join. And in case of a decision, only one option can be chosen.

    The actions 1 and 2 above, are also available from other locations in the application. I just need to make them available on the Add hotel activity.

    So how would I go about modelling optional actions that are available all the time during the flow of an activity? And why should it be done that way (if not obvious after reading) Also, does it matter if these optional actions are Atomic actions or CallBehavior actions?

    Like is said, I'm fairly new to UML, so it might well be possible that I interpret some things wrongly.

  • Michael Albers
    Michael Albers about 9 years
    Thanks for the quick answer. Your suggestion is very easy to understand. However, my issue is that after choosing Add loyalty program, I still need to be able to choose Add hotel chain. Can I instead of proceeding to the merge, return to Provide details? If so, does that mean the second lozenge can be omitted? I visualize the middle edge from the first lozenge going to the endpoint, the others going to the optional actions, and the outgoing edges of the actions going back to Provide details. Guess I just gave my self a hard time with this. You are definitely pushing me in the right direction.
  • Geert Bellekens
    Geert Bellekens about 9 years
    I would just go back to the decision from "Add loyalty program", so after that you can still go to "Add hotel chain" or directly to the merge node.
  • qwerty_so
    qwerty_so about 9 years
    I have update the image. You can also leave off the decision nodes and use [guards] in the transitions to show when to go which way. I did not know the condition so I did not use them in my sample diagram.
  • Michael Albers
    Michael Albers about 9 years
    This is what I came up with: link. I would appreciate feedback from you guys. I still need to add a guard that a hotel can only belong to 1 hotel chain. @geert: As you can see, I did choose to go back to the Provide details action.
  • qwerty_so
    qwerty_so about 9 years
    Fine so far except: Validate input should be an action and [Input incorrect] should be written as guard like before.