nus-cs2103-AY2021S2 / forum

10 stars 0 forks source link

Object Diagram when to use aggregation #356

Closed justgnohUG closed 3 years ago

justgnohUG commented 3 years ago

From these 2 code blocks in Week 8 Tutorial,

image

image

(Stock Item code block is included for relevancy) image

Alternatively, visit https://nus-cs2103-ay2021s2.github.io/website/schedule/week8/tutorial.html for full context.

The Actual Question I would like to clarify the relationship between Item and Inventory.

Given that Inventory has a List<Item> reference, I was wondering if Aggregation is possible here in the Object Diagram

image

PS: Diagram updated as aggregation direction was incorrect initially.

damithc commented 3 years ago

Yes, you can. That said, do note that we recommend not to use aggregation at all, in class or object diagrams. Aggregation doesn't add much value; it's just noise.

justgnohUG commented 3 years ago

Thank you for the reply Prof @damithc,

That said, I would think most of the time in the Exam especially, aggregation can be substituted for other forms of association, and a need for aggregation would be close to unnecessary?

Not trying to sniff out Exam questions, but more curious of the situations we would ever be "forced" to utilize aggregation.

damithc commented 3 years ago

In the exam, we do not expect you to use aggregation symbol when drawing class/object diagrams. However, you should still be able to interpret the aggregation symbol in a given diagram.