nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Additional practice questions for part 2: Sequence Diagram #983

Closed tankh99 closed 6 months ago

tankh99 commented 6 months ago

I have a couple of questions regarding the sequence diagram question. I will refer to the main function as the arrows from the left:

  1. for the creator().increase() function, is it the main function calling it, or is it the factory class calling it?
  2. Do we need an else block for alt paths in this case?
Screenshot 2024-04-24 at 7 22 41 AM
MarcusGitty commented 6 months ago
image

It can be split as Factory tempFactory = u.creator(); tempFactory.increase(1);

  1. It's the unit class calling it since u is of type unit.
  2. The unit class calls it's own creator method that returns a factory
  3. this returned factory class calls it's own increase 1 class
image

From the textbook, it seems that the else block can be ommitted.

tankh99 commented 6 months ago
image

It can be split as Factory tempFactory = u.creator(); tempFactory.increase(1);

  1. It's the unit class calling it since u is of type unit.
  2. The unit class calls it's own creator method that returns a factory
  3. this returned factory class calls it's own increase 1 class
image

From the textbook, it seems that the else block can be ommitted.

Thanks Marcus, this makes sense