nus-cs2103-AY2425S1 / forum

12 stars 0 forks source link

Question Regarding Sequence Diagram for use of `alt` frame for if statement #848

Open SeeYangZhi opened 4 hours ago

SeeYangZhi commented 4 hours ago

image

The textbook's defintion of alt frame – That is, it is acceptable for none of the alternative partitions to be executed but it is not acceptable for multiple partitions to be executed seems to contradict the incorrect answer in the above question. Should C be a correct option in this case?

Tkaixiang commented 2 hours ago

To add on to @SeeYangZhi 's question, must an alt path have >1 frames always or is it acceptable to only have 1 frame like in the image shown above? Also, must it always have an else frame? These are unfortunately not very clearly defined in the textbook image

zaidansani commented 2 hours ago

Must an alt path have >1 frames always

image

Hmm, interestingly, if I'm reading this right, the UML specification states that there only needs to have 1 frame minimum, and does not state anywhere differently. (Credit to: [StackOverflow]](https://stackoverflow.com/questions/21939324/difference-between-alt-and-opt-fragment-in-sequence-diagram))

At the same time -

image

the optional path mentions that it is semantically equivalent to an alternate with 2 options having the second be empty, implying that a second operand must exist for a alternate path, but there is no firm writing everywhere that an alternate path must have >1 operands. @Tkaixiang


To answer @SeeYangZhi's question, the issue lies with the word 'appropriate' IMO.

It would be appropriate for us to write the following code based on the sequence diagram. However, would it be appropriate for us to draw the diagram based on the code? If appropriateness specifically talks about interpretation instead of actual rules, I think it would not be appropriate to draw it as an alternate path instead of an optional path.

The diagram should indicate what is happening in the code, and it would be misleading (IMO) to indicate it as an alternative path when there is no alternative.


Would appreciate a clarification from you prof! @damithc

JoanneHing commented 1 hour ago

747 might be helpful for this as they are referring to the same question!