Search code examples
umlassociationsclass-diagramternarymultiplicity

How to model certain associations in UML?


I should portray the following connections between cinemas, movies and movie distributors in an UML class diagram:

  1. A movie distributor lends a certain movie to several cinemas.
  2. A movie distributor lends a certain movie to a certain cinema, but not to other cinemas.
  3. At most one movie distributor lends a movie to a cinema.
  4. But a movie for different cinemas can have different movie distributors.
  5. A movie distributor can lend several movies to the same cinema.

Right now my UML diagram looks like this: UML

I derived the multiplicities from the following statements:

  • class Movie Distributor - statement 3 from above (at most)
  • class Cinema - statements 1 and 2 from above: I interprete these statements as "a movie distributor lends a film to at least 1 cinema
  • class Movie: statement 5 (several movies)

I struggle definitely with statement 4 and I'm not sure about my interpretations of the other statements too.


Solution

  • You may be on the right direction for the multiplicities. However, did you spot the challenge of several classes being involved in the same association?

    To solve this you can:

    • introduce a fourth object that models the Rental, in addition to the Movie, Distributor and Cinema.
    • use a ternary association between the already identified classes.
    • use an association class to represent pne of the three clasdes. But this does not seem suitable here, as it would not aknowledge that movies, cinemas and disributors exist independently of their relationships.
    • use an association class to tepresent the rental

    Edit

    In view of your diagram, let's first remind the principles of multiplicity in ternary associations, since it's far from being obvious:

    The multiplicity says something about how many times an instance may be present in this associations for any given tuple of linked instances.

    Let's apply it successively. THis will without suprise confirm your own analysis:

    • For a given Distributor and a given Cinema, there can be 0..* Movies lent. That's (5).
    • For a given Cinema and a given Movie, there can be 0..1 Distributor making the lend. That's (3)
    • For a given Movie and a given Distributor, the lend can be for 1..* Cinema. That's (1) and (2). (This also means that it make no sense to lend no movie)

    The item 4 is missing, but it's only a consequence of the others. (4) means that we take a given movie:

    • Nothing says that a given Movie can have only one Distributor. So we are allowed to imagine cases with several distributors for the same movie, isn't it ?
    • Nothing says that a given Movie is shown only in one Cinema. So we are allowed to imagine the same movie in several cinemas.
    • Taking both together, we have a movie with several distributors and several cinemas.
    • Now nothing requires that there should be only one Movie for a pair of Cinema/Distributor (otherwise the multiplicity of Movie would be 0..1 and not 0..*
    • By deduction, a movie can be combined with several cinemas and distributors, with different distributors involved.