nus-cs2103-AY2122S2 / forum

14 stars 1 forks source link

Practice Quiz 1 #299

Closed domlimm closed 2 years ago

domlimm commented 2 years ago

Hello, could the wrongly selected option be correct too? As * multiplicity is 0..*.

Though, it shouldn't be the answer because in this object diagram shows it's just 1 to 1.

Thank you!

image

ngjunkang commented 2 years ago

Door is the one that is not compliant. Since there must be one Door.

jbkim1999 commented 2 years ago

In that case, should Object diagram capture all objects created from a class diagram?

I selected the above options as well because I thought not all objects need to be captured in an object diagram.

damithc commented 2 years ago

Hint: If you wanted to say "Every Table object must be associated with exactly one Door object (i.e., a Table object cannot exist without an accompanying Door object)", how would you show that in the class diagram?

damithc commented 2 years ago

In that case, should Object diagram capture all objects created from a class diagram?

Not necessarily. Depends on the multiplicities.

domlimm commented 2 years ago

Door is the one that is not compliant. Since there must be one Door.

Hey @ngjunkang! Could you please elaborate further? I don't see any Door object :')

Would both options that have Door work? Because we can't really tell the multiplicity. Unless I'm missing or not seeing something...

lzan98 commented 2 years ago

Door is the one that is not compliant. Since there must be one Door.

Hey @ngjunkang! Could you please elaborate further? I don't see any Door object :')

Would both options that have Door work? Because we can't really tell the multiplicity. Unless I'm missing or not seeing something...

hi @domlimm!

Not sure if this was what @ngjunkang meant, but I think it is because the 3rd option indicates that there must always be 1 door regardless of the number of Table objects. However, based on the question given, there is no association given between a door object and table object. So third option definitely cannot be true.

In contrast, second option is compliant because of the * - Meaning there could be 0 table objects, and it still complies with the question.

Or another way to think about it as Prof mentioned would be that for the given class diagram in option C, would the given object diagram in the question still be correct?

ngjunkang commented 2 years ago

@domlimm Look at the third option, the class diagram is trying to show that every Table class must be associated to any number of Chair and exactly one Door. However, the object diagram only shows the association between a Chair and Table object. For the third option to be correct, the object diagram needs to be like this: :Chair -- :Table -- :Door.

ckcherry23 commented 2 years ago

Hey @domlimm! For the second option, since it says that each Table can be associated with 0 to n Doors and the actual object diagram has 0 Doors, it is right.

Screenshot 2022-05-02 at 11 40 00 PM


But for the third option, since each Table must have exactly one door (compulsory association), and the object diagram has 0 Doors, it is incorrect.

Screenshot 2022-05-02 at 11 41 28 PM
domlimm commented 2 years ago

HELLO @lzan98 @ngjunkang @ckcherry23! Alright I understand guys. Thank you so much! WHOOPS YEAH MISSED THAT PART 😭

Will just close this now! Thanks again!

damithc commented 2 years ago

but I think it is because the 3rd option indicates that there must always be 1 door regardless of the number of Table objects.

@lzan98 this interpretation is not correct. When interpreting the multiplicity of one end, the other end is considered 'for each object of X' (not as "regardless of the number of X objects" as you have suggested). Consider the following multiplicity: image

When interpreting it, we don't care about the * at the other end. That end will be read as "For each Table object ...". So, the full interpretation is "For each Table object, there should be exactly one Door object".
Similarly, the other end is interpreted as "For each Door object, there can be any number (i.e., *) of Table objects connected to it".

All these object diagrams are compliant with the above class diagram: Diagram 1:

[_:Table_]---------[_:Door_]

Diagram 2:

[_:Table_]---------[_:Door_]

[_:Table_]---------[_:Door_]

Diagram 3 (a Door can exist without a Table):

                     [_:Door_]

Diagram 4:

[_:Table_]---------[_:Door_]-----------[_:Table_]

But these are not compliant: Diagram 5 (one Table cannot have two Door objects):

[_:Door_]---------[_:Table_]---------[_:Door_]

Diagram 6 (a Table cannot exist without a Door):

[_:Table_]
lzan98 commented 2 years ago

but I think it is because the 3rd option indicates that there must always be 1 door regardless of the number of Table objects.

@lzan98 this interpretation is not correct. When interpreting the multiplicity of one end, the other end is considered 'for each object of X' (not as "regardless of the number of X objects" as you have suggested). Consider the following multiplicity: image

When interpreting it, we don't care about the * at the other end. That end will be read as "For each Table object ...". So, the full interpretation is "For each Table object, there should be exactly one Door object". Similarly, the other end is interpreted as "For each Door object, there can be any number (i.e., *) of Table objects connected to it".

All these object diagrams are compliant with the above class diagram: Diagram 1:

[_:Table_]---------[_:Door_]

Diagram 2:

[_:Table_]---------[_:Door_]

[_:Table_]---------[_:Door_]

Diagram 3 (a Door can exist without a Table):

                     [_:Door_]

Diagram 4:

[_:Table_]---------[_:Door_]-----------[_:Table_]

But these are not compliant: Diagram 5 (one Table cannot have two Door objects):

[_:Door_]---------[_:Table_]---------[_:Door_]

Diagram 6 (a Table cannot exist without a Door):

[_:Table_]

Thank you for the detailed clarification prof!