nus-cs2103-AY1920S1 / forum

Forum
1 stars 1 forks source link

Questions on association classes #193

Open KendrickAng opened 4 years ago

KendrickAng commented 4 years ago

In the mock practice paper (part II), the answer for 1a is given as follows:

image

Firstly, answer for question 1a uses a Trade class which is associated to two players and two collections of assets. Is this not just an alternative notation for association classes? In that case, could the association class be drawn as such:

image

Secondly, can association classes be additionally associated to other classes not part of the association (i.e associated to asset, beyond just between two players)?

Thirdly, for 1b: are we allowed to draw dependencies in an object diagram? I attempted to replicate the association class drawn above in object diagram form, but I’m not sure of its correctness:

image

Fourthly, can we use multiplicities in object diagrams (shown above) instead of drawing associations to two objects of the same class (shown below):

image

Thank you!

damithc commented 4 years ago

Good questions @KendrickAng

Firstly, answer for question 1a uses a Trade class which is associated to two players and two collections of assets. Is this not just an alternative notation for association classes? In that case, could the association class be drawn as such:

image

Note that a Trade object stores information about an association between four objects. As the association notation cannot handle such cases, we can use normal associations instead. Also note that your diagram shows all 4 associations already, in which case showing another association class notation is redundant. In general, when the situation doesn't fit the association class scenario, you can fall back on normal associations.

Secondly, can association classes be additionally associated to other classes not part of the association (i.e associated to asset, beyond just between two players)?

Following from the answer above, it is also possible to frame a 4-object relationship as an association class between two objects that involve two other objects. You diagram matches that framing, but only if you remove the two green associations. But I recommend you do not go this way because there are additional rules about association classes that we did not cover in the module and those rules can make such a framing incorrect depending on which association you pick to frame as the association class.

Thirdly, for 1b: are we allowed to draw dependencies in an object diagram? I attempted to replicate the association class drawn above in object diagram form, but I’m not sure of its correctness:

image

Don't draw dependencies in object diagrams. The purpose of an object diagram is to show the object structure at a given time.

Fourthly, can we use multiplicities in object diagrams (shown above) instead of drawing associations to two objects of the same class (shown below):

No. multiplicity is a rule specified in the CD; the OD should follow the rule, not show the rule again. The OD should show the actual links between objects.