nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Additional practice questions for part 2: Class Diagram #1040

Closed Jaspertzx closed 6 months ago

Jaspertzx commented 6 months ago

image When do we know to use the composition symbol? My intuition here would be:

  1. Handout <>------- Section (<> is the composition symbol) As when the Handout is deleted, it would make sense logically for the Section to be deleted as well, something like the folder/subfolder example in the notes.
  2. There is no composition between Handout and Brochure, as there is a cyclical link where Brochures must point to exactly one handout, and a Handout can be referenced by a any number of brochures.

Is my intuition correct? Or is there something I'm missing here. Thank you in advance!

camille-readbean commented 6 months ago

I think number 2 will be subjected to the same reasoning as number 1 though? A brochure doesnt make sesne without the Handout it is a part of?

damithc commented 6 months ago

In this kind of exam question, if composition is expected, there will be additional hints to indicate a whole-part relationship (which is the definitive requirement for composition). For examples, phrases such as composed of, part of.

Related comment https://github.com/nus-cs2103-AY2324S2/forum/issues/915#issuecomment-2078669479

Jaspertzx commented 6 months ago

Thanks Prof, just one last quick question, if it is in a whole-part relationship, can the dependency line from Section to Handout be removed? Section has a static method with a Handout Object, meaning that it would be depend on the Handout Class. Does this composition relationship capture this dependency as well? image

Included a photo just in case it's too confusing.

damithc commented 6 months ago

Section has a static method with a Handout Object, meaning that it would be depend on the Handout Class. Does this composition relationship capture this dependency as well?

@Jaspertzx

classDiagram
    Foo *--> Bar
classDiagram
    Foo --> Bar

In both cases above, there is no point showing Foo ------> Bar dependency, as there is already an association in that direction. So, the diagram below is incorrect. Furthermore, this is nothing to do with composition. It's dictated by the navigability of the association, irrespective of whether it is also a composition or not.

classDiagram
    Foo --> Bar
    Bar <.. Foo

But it doesn't also imply a dependency in the reverse direction Foo <------ Bar So, if there is a dependency in the reverse direction (due to some other factors), you need to show it separately, like this:

classDiagram
    Foo --> Bar
    Bar ..> Foo
Jaspertzx commented 6 months ago

Understood, thank you so much Prof!