nus-cs2103-AY2122S2 / forum

14 stars 1 forks source link

Drawing alternate paths in sequence diagrams where return statement exists in branch #309

Open bingsen0806 opened 2 years ago

bingsen0806 commented 2 years ago

I am having some problems when attempting to draw this sequence diagram in AY1819S1 past year, the question is shown below:

image

Below is my attempt, I am unsure if it is correct, but I have 2 questions regarding my attempt.

image

  1. Should the bottom border for alternative paths moved up a bit (as shown by red line), such that the border for alternative path ends before the dotted line representing the return from generate()? I am tempted to move it up because the box for alternative path starts inside the activation bar of generate(), and it seems like the box should also end in the activation bar. However, if you look at the code, the return statement is inside the else branch, so it also makes sense for the activation bar and dotted line to appear before the closing of the alternate path. Therefore, I am confused as to which one is correct.

  2. Is the dotted line marked as (2) in the diagram necessary?

ckcherry23 commented 2 years ago

I think (1) is a better choice for the return from generate() and (2) is not required.

Since it is possible for us to refactor the code such that we save the task and return it outside the if-else branch condition while keeping the same code behavior, I think the return can be moved outside the alt frame.

damithc commented 2 years ago

Both are fine. Personally, I would opt for the version that matches the code more closely i.e., 2.