nus-cs2103-AY2021S1 / forum

20 stars 2 forks source link

Quiz 8 part 1 #488

Closed chunyongg closed 3 years ago

chunyongg commented 3 years ago

Hi there,

I encountered some issues while reattempting the quizzes.

image

In Q6, Since Bot has an attribute with Mat (and vice versa), why is bidirectional navigability wrong?

image

In Q7, Since Mat holds a reference to Bot, why is this class diagram incorrect?

In Q20, under Bot-Bot association, image

image

I interpreted this as "One or zeroBot object can be associated with up to two Bot objects", which sounds reasonable to me. But the answer is wrong. How should this be interpreted?

Miscellaneous question

On the concept of multiplicities with navigability, do we need to provide a multiplicity value for the class that is aware of the other class? For instance, if a class resembles the following structure:

image

Mat is aware of Bot and is associated with up to 5 Bot objects, which indicates a multiplicity of 5. While Bot is associated with 0 or 1 Mat objects. From this example, it seems that in the case where single direction navigability is involved, association would always be a case where the class that is aware of the other class always has a multiplicity of 0..1. Is this understanding correct?

Thank you.

GeNiaaz commented 3 years ago

Q6 and 7:

I believe the fact that the multiplicity of Bot is included in Mat is an example of Mat knowing some details about Bot. However, for Bot to simply contain an uninstantiated instance of Mat does not demonstrate anything related to the inner details of Mat. (Correct me if I'm wrong anyone)

Q20:

To avoid ambiguity, I will refer to the bot containing the others as the primary and the ones being contained as the secondary 0..2 means that up to 2 secondary bots can be associated with 1 primary bot. 0..1 means that a primary bot may be associated with a secondary bot, or not at all.

Miscellaneous:

As for the last question, I am not sure what you are asking, could you possibly provide more details?

sudogene commented 3 years ago

To add on...

Q6 and 7, I think the question was asking for diagrams that represent the highlighted code only. E.g. In Q6, the bidirectional navigability is not minimally representing the highlighted code in Mat class.

Q20, Since the backup is an attribute of a Bot, the navigability will be "BotWithBackup --> Backup". And since the question said that a Bot may act as the backup of no more than two other Bots, the multiplicity (shown in Q20) should be swapped.

Misc, 0 should only be valid if the attribute can be null. There may be cases where the multiplicity is a fixed 1 and not 0..1 IF there is some sort of defensive programming that forces it.

chunyongg commented 3 years ago

Thanks for the responses! To clarify my miscellaneous question further, here's another attempt to phrase it: would there be ever be a case where a single direction navigability exists from A->B, yet A has a multiplicity of more than 1 (i.e. a B object can be associated with more than one A object?)

sudogene commented 3 years ago
class A {
  B b;
  public A(B b) {
    this.b = b;
  }
}

B b1 = new B();
A a1 = new A(b1);
A a2 = new A(b1);
A a3 = new A(b1);  // ... And so on

If I understand your question, this code example shows that the B object can be associated with any number of A objects. The multiplicity would be *.

damithc commented 3 years ago

image

In Q6, Since Bot has an attribute with Mat (and vice versa), why is bidirectional navigability wrong?

Based on variable names, these are two different associations (one is about helpers, while the other is about partners) that happen to be in opposite directions. A bi-directional association is a case of the same association being tracked by both objects e.g., you know me as your teacher and I know you as my student -- it's same association and the person at each end is aware of the other.

image

In Q7, Since Mat holds a reference to Bot, why is this class diagram incorrect?

The question asks for association role. The diagram doesn't show any association role.

In Q20, under Bot-Bot association, image

image

I interpreted this as "One or zeroBot object can be associated with up to two Bot objects", which sounds reasonable to me. But the answer is wrong. How should this be interpreted?

When you interpret a multiplicity, you take the other end as 1. You should not interpret both at the same time. See around 14 minutes in the video here

Miscellaneous question

On the concept of multiplicities with navigability, do we need to provide a multiplicity value for the class that is aware of the other class? For instance, if a class resembles the following structure:

image

Mat is aware of Bot and is associated with up to 5 Bot objects, which indicates a multiplicity of 5. While Bot is associated with 0 or 1 Mat objects. From this example, it seems that in the case where single direction navigability is involved, association would always be a case where the class that is aware of the other class always has a multiplicity of 0..1. Is this understanding correct?

A normal variable can hold 0 or 1 object. Hence, it results in 0..1 multiplicity at the other end of the association. Not sure if that's what you are getting at. Let me know if not.

chunyongg commented 3 years ago

Thank you for the responses!