Question

I understand how sequence diagrams represent the interactions between objects by calling each other functions and the timeline trace of the function calls. I am not sure how to represent this if the function call happens to be recursive.

Put simply, I have a class with a recursive function defined to calculate the Fibonacci numbers, given the value of n as parameter. How to show the two recursive calls on sequence diagram?

Also, should the sequence diagram should be generic? I mean, it should depict for all values of n and does not need to be adapted for different values of n, right?

Was it helpful?

Solution

Here are examples of recursive calls: self message(non recursive) vs self recursive message

Tool support is also given, for example: http://www.sparxsystems.com/enterprise_architect_user_guide/9.0/standard_uml_models/recursion.html

I think I'd not specify a recursive call unless I am really sure I need the call to be recursive. Then the developer may decide for himself whether to implement a recursive call or an iteration. If I need the recursion, a hint (using a note) might be helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top