7

UML ダイアグラムで多重度を示すことについて質問があります。

アニメーションのリストを持つ SpriteObject クラスがあります。SpriteObject は 0..* のアニメーションを持つことができます。すべてのアニメーションは SpriteObject 内で作成され、単独では存在しません。

これを多重度でどのように示すべきか、100% 確信が持てません。Webを検索した後、次の3つのオプションが見つかりました。

オプション 1: すべての SpriteObject には 0 個以上のアニメーションがあるため、多重度はこのように示す必要があります。アニメーションは SpriteObject の存在についての手がかりを持たないため、SpriteObject の側に示される多重度はありません。 ここに画像の説明を入力

オプション 2: 1 つの SpriteObject に 0 個以上のアニメーションがあるように、2 つのクラス間のローカルな関係を示す必要があるため、このように両側で多重度を示す必要があります。 ここに画像の説明を入力

オプション 3: 多重度をこのように両側に示す必要があります。これは、多重度を読み取って全体 (ゲーム) の一部として理解できるようにする必要があるためです。ゲームには 0..* SpriteObject を含めることができ、SpriteObject には 0..* アニメーションを含めることができます。そのため、0..* SpriteObjects には 0..* アニメーション があります。ここに画像の説明を入力 どのオプションが正しいか誰か教えてもらえますか? (もしあれば)

4

4 に答える 4

8

[Edit]

It should be Option 1. This is a composition relationship

What this means is that SpriteObject contains and manages the lifetimes of the Animation objects.

As an example.

public class SpriteObject : IDispose
{
  private List<Animation> animations;

  // constructor
  public SpriteObject()
  {
    animations = new List<Animations>();

    // initialise the list
  }

  public ovveride Dispose()
  {
    // clear list
  }
}

If this is a an aggregation relationship.

enter image description here

Take note of the symbol, the hollow diamond. This is an aggregagtion relationsip. What this means is that an instance SpriteObject can have zero or more instances of Animation, but the lifetime of the Animation objects is not dependent on the lifetime of the SpriteObject.

A C# code example would look like:

public class SpriteObject
{
  private List<Animation> animations;

  // constructor
  public SpriteObject(List<Animation> animations)
  {
    this.animations = animations;
  }
}
于 2014-01-27T01:44:40.290 に答える
1

Animationインスタンスは単独では存在できないと述べたので、オプション 3 を直接拒否します。同じインスタンスが複数のSpriteObjectインスタンスに関連している可能性があることに非常に驚いています。

次の質問は、AnimationインスタンスがそのSpriteObject所有者を参照しているかどうかです。そうでない場合は、オプション 1 を選択します。

于 2014-01-26T11:33:06.030 に答える