nus-cs2113-AY2122S1 / forum

3 stars 1 forks source link

Regarding Association in class diagrams #160

Open andrewtkh1 opened 2 years ago

andrewtkh1 commented 2 years ago

Hi Sir,

Regarding the question below, why is option c wrong? From my understanding of association, both lid & container are associated with each other, regardless of the navigability.

image

okkhoy commented 2 years ago

The key thing is the word must. Since the multiplicity is not given as 1, it can't be must. That is why it is incorrect.

andrewtkh1 commented 2 years ago

Ahyeee, on a side note, is my understanding of association right? In the sense that association is always bi-directional, regardless of navigability. So for the above case, both Lid & Container are associated to one another. I just can't use the word "must".

okkhoy commented 2 years ago

Association is a connection between classes/objects. So yes, if there is an association between 2 classes then they are connected. Your understanding in the original post is correct here. (both lid & container are associated with each other)

The direction aspect comes from navigability (or the arrowhead); so you can't say the association is bi-directional without considering navigability.

andrewtkh1 commented 2 years ago

Hmm then does it mean that it is not right for me to say that Lid is associated with container since the navigability is only 1 way?

okkhoy commented 2 years ago

No, your understanding is incorrect. Association => connection. So there is a connection between lid and container. Navigability => who holds the reference of the other; container holds the reference to lid.

andrewtkh1 commented 2 years ago

Ahh so my statement Lid is associated with container actually true as there's a line connecting?

okkhoy commented 2 years ago

yup

andrewtkh1 commented 2 years ago

Okie Thank you!.

I'll leave this thread open for others to refer to.