2

I'm working on a sequence diagram for a layered system that has a tree hierarchy. Now I have a process that works itself recursively down the tree. Meaning calling the same function on a child object.

I'm talking about a tree like this:

-layer n
   -layer n-1
       -layer n-2
           -...
       -layer n-2
           -...
   -layer n-1
       -layer n-2
           -...
       -layer n-2
           -...

Its easy to visualize a recursive process in the single object, but I could figure out how I would visualize recursive process that recursively calls itself on a lower layer object and so on. Is this even possible with an UML sequence diagram?

3

1 Answer 1

3

A sequence diagram doesn't represent a process, but a sequence of interaction between objects, where an object is a specific instance of a class.

Therefore, the representation of the recursion would be similar to the way you represent it in code: in one diagram you would only show what happen at one level of your recursion:

enter image description here

If there is no other object involved in the recursion, you would use a self-message.

5
  • Why are the execution specifications shifted to the right (left:node and right:node)? Is this a bug in the diagram or part of the notion of recursion? Commented Aug 22, 2020 at 15:33
  • @Fuhrmanator No, this is a bug in the diagram. Perhaps related to the way I copied and resized it.
    – Christophe
    Commented Aug 22, 2020 at 16:57
  • What if the number of child nodes is variable? Commented Jun 2 at 16:24
  • 1
    @MehdiCharife if you have a variable number of child nodes, you probably will iterate through them. You may then have a look at this other question on Stack Overflows: stackoverflow.com/q/74324899/3723423
    – Christophe
    Commented Jun 2 at 21:16
  • @Christophe Thanks for your response. I'll look into it. Commented Jun 2 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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