nus-cs2103-AY2021S2 / forum

10 stars 0 forks source link

When to use composition? #352

Open hengyongming opened 3 years ago

hengyongming commented 3 years ago

As seen from the images below, why is there a need for composition for one and not the other although both are a list of things?

image image

tlylt commented 3 years ago

I think sometimes it is ambiguous as to whether the relationship is whole-part or not.

If I remember correctly, it was explained that the second one has a clearer whole-part relationship because of the comment // 1 or more tasks which are parts of this action.

I do agree that the first image might be considered whole-part as well, given the fact that the collection variable is named parts. However, if the variable is not named as parts (e.g. named as items), I will be more confident to say that it is not whole-part.

damithc commented 3 years ago

IIRC, the Box example covers basic class diagram notation only (composition is not among basic notations) In general, use composition if there is strong evidence of a whole-part relationship.