在UML中使用多重性而不具备导航性是否正确的图表?

huangapple go评论47阅读模式
英文:

Using multiplicity without navigability in UML is correct diagram?

问题

I can see many UML example like above diagram.
I can understand that

  1. Class A has navigability to B with multiplicity of 10.
    But I can't understand that
  2. Class B has no navigability to A but has multiplicity of 5..7.
    Is it possible has multiplicity without navigability in UML?

I can implement case 1 like below.

class A {
public:
    B b[10];
}

But how can I implement case 2? No navigability but has multiplicity?
I am totally confused of case 2. What am I missing?

英文:

在UML中使用多重性而不具备导航性是否正确的图表?

I can see many UML example like above diagram.
I can understand that

  1. Class A has navigability to B with multiplicity of 10.
    But I can't understand that
  2. Class B has no navigability to A but has multiplicity of 5..7.
    Is it possible has multiplicity wihtout navigability in UML?

I can implement case 1 like below.

class A {
public:
    B b[10];
};

But how can I implement case 2? No navigability but has multiplicity?
I am totally confused of case 2. What am I missing?

答案1

得分: 2

是的,可以在没有导航性的情况下拥有多重性。

导航性只是对在运行时轻松查找另一端的实例做出的承诺。没有导航性的承诺(甚至在另一端用X明确表示没有导航性)并不会改变关联的存在,因此也不会改变多重性。

第二种情况的实现,例如,可以使用在B中指向A的指针向量来实现导航回去(导航性会存在,但只是没有指示出来)。另一种实现方式可能是在A中使用指向B的指针向量,以便B可以被多个A共享,而其他机制确保它被3到7个A共享(没有导航性,但多重性被强制执行)。

英文:

Yes, it is possible to have a multiplicity without navigability.

Navigability only makes a promise about the ease at runtime to find instances at the other end. The fact the there is no promise on navigability (or even an explicit absence of navigability with a X at the opposite end) does not change the existence of an association and hence the multiplicity.

The implementation of 2) could for example be done with a vector of pointers to A in B to navigate back (the navigability would exist, but is simply not indicated). Another implementation coukd be to use in A a vector of pointers to B, so that B can be shared, and some other mechanism make sure it is shared by 3 to 7 A's (no navigability, but multiplicity enforced)

huangapple
  • 本文由 发表于 2023年3月1日 13:54:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600017.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定