Z.J
Z.J

Reputation: 349

Composition or aggregation

Please take note of my class diagram. It shows an excerpt from a software for the management of movie showings in a cinema and comes from a study book.

enter image description here

The study book explains that there is a composition between the room and the seat. If a cinema employee deletes a room, the seats must of course also be deleted.

About my problem: I want to extend the example with the classes Showtime, Reservation and Movie. However, a reservation always refers to a concrete seat. I would pass a reference to a seat to the reservation: enter image description here

In this case, can the composition between Room and Seat still remain or does it becomes an aggregation?

Translated with www.DeepL.com/Translator (free version)

Upvotes: 2

Views: 190

Answers (1)

Christophe
Christophe

Reputation: 73366

Preliminary side remark: for the sake of simplicity, you could remove all the shared aggregation (white diamonds), because UML doesn’t define their semantic and they do not fundamentaly change the meaning compared to ordinary associations.

Let’s look at the whole scenario and keep the composite aggregaton. The consequence is the following:

  • If you delete a room, the seat would die. This sounds logic, because the seat does not make any sense without the enclosing room.
  • If you accept that a room gets deleted if still in use by a showtime, you accept that some showtimes may not be linked anymore to a room.
  • In a similar manner, this may propagate to the reservation, since some reservations would loose their link to a seat.

Now is this scenario a problem? I routinely have a reservation for a flight without the reservation being linked to a seat. So it is up to you to decide how you want to handle it:

  • You could constrain the deletion of the room to require that it is not linked to any showtime. You therefore avoid the described situation.
  • You could accept any room deletion, if you decide to offer some reallocation functions that would allow to deal with showtime and reservations without room and seat (at least temporarily) and reassign a showtime and the reservation to a different room.

You may even go further and opt for a mixed scenario, and accept that deletion of the room is possible if no showtime exist in the future (active showtime) bust simply do not care for for reservations on past showtimes.

Upvotes: 1

Related Questions