Search code examples
umlsequence-diagramvisual-paradigm

Can this diagram represent an Iteration/for each in a Collection? Sequence Diagram or Activity Diagram?


i've this method findNegozio(insertID) used to find the element with insertID in a Collection. So, findNegozio(insertID) is an operation that is often referred to in my sequence diagrams so I thought I would illustrate it as a sequence diagram. The idea is to represent an iteration on a collection and take only the element that matches with the entered ID.

Could this be a good way to represent my idea? is it useful to represent a frequent step of some sequence diagrams?

EDIT: Maybe with only one step is better OPT instead of ALT.

enter image description here

mine code


Solution

  • First three remarks :

    • For me your code is invalid because a return is missing after the loop => I suppose a variable result is added and initialized to null, set to the found item if exist, and finally used for a final return.

    • Are you sure findNegocio is not static ?

    • Why findNegocio is defined on Negocio and not on GestoreNegocio ?

    A sequence diagram shows an interaction (partially or not) and focuses on message interchange between lifelines.

    From the definition of your operation it is needed to decide whose messages are enough interesting to be shown in your sequence diagram. I don't think the details concerning the list and iterator have to be shown, they are very classical, the goal is not to explain how to work with Java builtin classes.

    To break the loop you have the fragment break, so your sequence diagram can be (I added a caller because my tool does not manage lost/found messages) :

    enter image description here

    But perhaps the main information shown is the use of GestoreNegocio and the loop by itself is not really interesting ?