nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

How to interpret a sequence diagram without return value #969

Closed drustanyjt closed 6 months ago

drustanyjt commented 6 months ago

In this sequence diagram from the textbook, the blue return arrow (from the Minefield's activation bar) and the green return arrow (from the Label's activation bar) both have no return value.

image

For the blue return arrow the context seems clear, it is returning the new Minefield object being created.

Q1. For the green return arrow above, if there is no return value, does this just mean there is nothing returned from the activation, i.e. a void function.?

Furthermore, the textbook states that the return arrows are optional, but did not talk about return arrows with no return values. image

Q2. Are there situations where it is fine to draw a return arrow, while omitting its return value even if there is something being returned?

To me it seemed like if a return arrow is drawn, and there is something being returned, then the return value should be mentioned as well, if not there is some ambiguity as to what the return arrow signifies and there would have been no point drawing the return arrow to begin with.

Textbook notation for sequence diagrams:

image

itstrueitstrueitsrealitsreal commented 6 months ago

In my tutorial, my tutor mentioned that the return line, if there was no return value, represented a "handover of control" from the callee to the caller in a sequence diagram.

drustanyjt commented 6 months ago

Hmm @itstrueitstrueitsrealitsreal by that did you tutor mean that nothing is being returned either? I would assume that all return lines should indicate "handover of control", since that's why the activation bar can end after the return arrow (if there was a return arrow, and control is not handed over, then there is a contradiction because it means the function has not actually returned yet).

itstrueitstrueitsrealitsreal commented 6 months ago

Yep, my tutor was referring to this case from tutorial 8, where personList.addPerson(p) is called:

Screenshot 2024-04-23 at 4 13 09 PM

I would assume that all return lines should indicate "handover of control", since that's why the activation bar can end after the return arrow

I'm not too sure about the claim that the activation bar can end after the return arrow though...

Screenshot 2024-04-23 at 4 21 01 PM
drustanyjt commented 6 months ago

Okay thanks for that!

Anyone able to answer the second question?

Q2. Are there situations where it is fine to draw a return arrow, while omitting its return value even if there is something being returned?

tankh99 commented 6 months ago

Okay thanks for that!

Anyone able to answer the second question?

Q2. Are there situations where it is fine to draw a return arrow, while omitting its return value even if there is something being returned?

I think that it's also fine to draw a return arrow without omitting the return value. The return value is optional after all.

However, I'm not sure in what cases this would be helpful

damithc commented 6 months ago

@drustanyjt the return arrow and the return value are optional. You can omit both or show the arrow without the value, if the omitted arrow/value is not important to the purpose of the diagram. As others pointed out, the return arrow indicate the return of control. So, it can be present even when there is no return value.

drustanyjt commented 6 months ago

Thanks prof @damithc!

Hmm back to question 1:

Q1. For the green return arrow above, if there is no return value, does this just mean there is nothing returned from the activation, i.e. a void function.?

image

Would it be more accurate to say that we cannot be sure if anything is being returned by the call to the Logic object's newGame() method. All we can say is that if an object is returned it is not important to this diagram? The only thing we can say for certain is that the green arrow indicates the return of control back to the caller of the newGame() method?

damithc commented 6 months ago

Would it be more accurate to say that we cannot be sure if anything is being returned by the call to the Logic object's newGame() method. All we can say is that if an object is returned it is not important to this diagram? The only thing we can say for certain is that the green arrow indicates the return of control back to the caller of the newGame() method?

@drustanyjt that's correct. In the exam, if the return value matters to answering the question. we will specify if the return values need to be shown in the diagram.

drustanyjt commented 6 months ago

I see, thanks prof @damithc and everyone!