0

だから私はこの質問を持っています、私はしばらくの間立ち往生しています。いくつかのビジネス ルールに基づいて関係を描画し、多重度も含める必要があります。質問は次のとおりです。

映画には、主演が 1 人、共演者が 2 人、または 10 人以上が一緒に見つめている映画があります。スターは少なくとも 1 つの映画に出演している必要があります。

今までこんな関係を築いてきましたが、

映画 ---------------------------1..* スター

映画とスターの関係の多重度はどうあるべきですか? 私はそれが1..2または11..*の線に沿ったものであることを知っています

これら 2 つを組み合わせて 1..2..11..* の多重度を取得できますか?

助けていただければ幸いです。

ありがとう!

4

1 に答える 1

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.

于 2014-04-25T12:06:21.260 に答える