0

So I have this question, which I have been stuck on for some time. I have to draw a relationship based on some business rules and include the multiplicities as well. The question is as follows:

A movie either has one star, two co-stars, or more than 10 people staring together. A star must be in at least one movie.

I have gotten this relationship so far,

Movie—--------------------------1..* Star

How should the multiplicity for the Movie to Star relationship be like? I know that its something along the lines of 1..2 or 11..*

Can I combine these 2 to get a multiplicity of 1..2..11..* ?

Help will be appreciated.

Thanks!

amias
  • 33
  • 5

1 Answers1

0

An extract from the formal UML specification:

"A multiplicity is a definition of an inclusive interval of non-negative integers beginning with a lower bound and ending with a (possibly infinite) upper bound."

So, you can only have one continuous segment as a multiplicity.

In your case I would use 0..* on both ends and specify these special restrictions separatelly. You can specify them more or less formally. Some ideas:

  • formal way: using preconditions, postconditions and invariants, eventually in OCL (please google these terms if you like)
  • informal way: using simple textual notes or class/method descriptions.

This logic could be further implemented in a Movie's method like addStars(Star[]), in order to centralize it. There are a lot of correct solutions however.

Maybe you've noticed that I've recommended 0..* instead of 1..*. This is just a suggestion leading to much more flexible solution. Lower bound of 1 is just too restrictive and should be used only when really necessary (Parent-Child might be an example, Child cannot be born with no Parent). Its value 1 on the Star's end would mean that at least 1 Star must be linked to the Movie in the process of its creation! I find it pretty ugly. What if no Stars are created yet in the system?

What if a Movie is created as a wish-list or the lineup is simply unknown in the time of creation? What if the Movie simply does not have any Stars? :)

By leaving both boundaries on 0, you can create Movies and Start independent of each other. You can always link them later, making your system much more flexible and user-friendly.

Aleks
  • 5,674
  • 1
  • 28
  • 54