0

Below is the problem for which I have created a UML diagram with Staff as superclass and waiter, manager and hosts as subclasses, I understood other parts, except for the relation between table and cover classes, should it be Aggregation(or composition) or Association.

Rough UML sketch enter image description here

There are three kinds of staff members, managers, waiters, and hosts. All the staff members have a staff ID and a telephone number. Managers are also able to add and remove waiters and hosts from the system.

Tables: The tables in the restaurant each of an ID number and a number of seats. Each table is assigned to a waiter, and waiters can have any number of tables. Each table will have a number of covers (see below) that must not exceed the number of seats. The Table class should have a method to check if it is a valid seating.

Covers: Each customer that comes into the restaurant should be represented as a cover. Each cover should have a cover ID, a table number, and a food order.

  • 1
    It would appear your house/office is on fire. – MetaFight Apr 27 '16 at 20:11
1

In UML, aggregation and composition are variants of the association. Association is a "has a" relationship. Aggregation is a "part of" relationship. Composition is a stronger form of Aggregation, where the parts cannot exist without the whole.

Since you know that a Cover has a Table, you have at least an association. However, can a Table exist without a Cover or can a Cover exist without a Table? If the answer to either of those is "yes", then you do not have a Composition. Next, ask yourself if a Cover is part of a Table or if a Table is part of a Cover. If "yes", then you have an aggregation. If "no", you have a simple Association.

I would suggest that your example is one of an Association. The next thing to figure out is directionality of the Associations. Associations can be bidirectional (the object on either end knows about the object on the other end) or unidirectional (one object knows about the other object, but not the other way). For example, the relationship that you are showing between Waiter and Table is a bidirectional Association.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.