sun_say
sun_say

Reputation: 89

Displaying a selection from a list in a class diagram

I'm making a diagram that shows the following:

Every day the student makes an order in the cafeteria, they can choose the full menu for today (for example, soup, sandwich, dessert, drink), as well as only some dishes from the menu (for example, only soup).

How to display this on a class diagram. Here my diagram. Should there be a relationship between the order and the menu or the order and the dishes?

my diagram

Upvotes: 3

Views: 1224

Answers (2)

Christophe
Christophe

Reputation: 73530

In complement to Bruno's excellent answer, I'd like to add for the records that your requirements are very ambiguous. For example:

  • Can a student take the full menu and additional items (e.g.second dessert)?
  • Can a student take a free menu with several time the same item?
  • Is the price of an item the same if taken in the full menu or taken separately? Is there really an item price or does the menu price prevail?
  • Does a menu fully specify the meals contained, or does the student have to say which soup or sandwich he/she wants?
  • Are non-full menus also represented by menu instances (e.g. is there a full menu, a light menu with just soup and sandwich, etc...)?

Depending on your answers, there are many possibilities to model this. For example:

  • If the menu is just a mean to select the items without any effect on the item price, you do not need any reference to the menu in your order.
  • If the menu is a self contained list of products that cannot be changed, or if the menu is a template that allows user to create a personalized menu, you do not need any reference to the mean in your order.
  • In the other cases, you may need both a reference to the items and the reference to the menu (if extra items without menu price conditions are allowed)
  • For the ultimate flexibility, you can design the menu according to the composite pattern, that allows the menu to be processed as an item (with a price), like any other items in an order, despite being composed of several meals. Be aware that, while being very beautiful, it adds some complexity.

Upvotes: 2

bruno
bruno

Reputation: 32596

Should there be a relationship between the order and the menu or the order and the dishes?

If you only have a relation between Order and Menu you have no way to know which dishes the student does not want, so if you have that relation you also need an other relation to indicate the (un)wanted Meal, but having that additional relation makes the relation between Order and Menu useless.

So have a relation between Order and Meal, but no (direct) relation between Order and Menu.


Out of that :

  • Is ordersType useful ? Also to have a composition to it has no sense because enum items always exist

  • A Menu is in relation with several Meal so the corresponding multiplicity must be 1..*

  • A Pupil can have several Order (multiplicity '*') so it seems several instances of Menu can exist at the same time, then a Meal can be part of several Menu so the corresponding multiplicity must be 1..* too.

  • The price of a Meal is an int, seems strange

  • The date of a Menu/Order is a double, seems strange too

  • The numClass of a Pupil is a string, strange if num means number

Upvotes: 2

Related Questions