nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Clarifications about class and object diagram #1047

Closed cheahTJ closed 6 months ago

cheahTJ commented 6 months ago

Hi, I have a these following few questions to clarify:

  1. Understand that parameters of method can be included: add(X), but is it WRONG to not have it?
  2. It is ok to show the return type of methods: getItemCount():int, however if the method is void, will it be represented as such count():void
  3. ON the same note as 2, if shown in the exams that some methods show the return type, but some methods never show in teh same diagram: add():int, minus():int, multiply(), will this be considered as wrong? (if let say we have to decide if such class/object diagrams with such methods show are correct or not)
  4. Are there any tricks to know what to EXCLUDE from an object diagram from a class diagram? The tutorial example seems a little hard to grasp, so i was just wondering if there are any tips on this
jannaleong commented 6 months ago

hi, im not too sure about 1 and 3 but for point 2, i believe if the method returns void, there is no need to indicate the return type.

For point 4, I believe when we compare class vs object diagrams, we exclude the methods and the multiplicities from the object diagrams. I think this section from the textbook could be helpful in distinguishing the two. https://nus-cs2103-ay2324s2.github.io/website/se-book-adapted/chapters/uml.html#object-vs-class-diagrams

Hope it helps!!

damithc commented 6 months ago
  • Understand that parameters of method can be included: add(X), but is it WRONG to not have it?

We encourage the unofficial notation (...) to indicate parameters have been omitted. Otherwise there is no way to differentiate between a method that doesn't have parameters and a method that omits parameters.

  • It is ok to show the return type of methods: getItemCount():int, however if the method is void, will it be represented as such count():void

Yes

  • ON the same note as 2, if shown in the exams that some methods show the return type, but some methods never show in teh same diagram: add():int, minus():int, multiply(), will this be considered as wrong? (if let say we have to decide if such class/object diagrams with such methods show are correct or not)

There will be no such questions In general, you can omit details not relevant to the purpose of the diagram.

  • Are there any tricks to know what to EXCLUDE from an object diagram from a class diagram? The tutorial example seems a little hard to grasp, so i was just wondering if there are any tips on this

For this, see @jannaleong's answer

cheahTJ commented 6 months ago

Got it thank you ! @damithc @jannaleong

cheahTJ commented 6 months ago

Sorry but what I dont get for question 4 is that from a class diagrams (like the one in tutorial), when we are needed to draw an object diagram, do we redraw the object diagram from scratch or shall we follow what was drawn in the class diagram already but we modify some things (like in the tutorial question, we omit the drawing of Item object beacuse the StockItem is already an Item, and Inventory object can jsut point directly to StockItem instead). So yeah i was just wondering if there are tricks to drawing object diagrams from a question in general