UML 类图中 n 到 1 个对象的关联
可以肯定地说,在 UML 类图中,如果存在 n 到 1 个对象的关联,则关联箭头从与 n 个对象关联的类指向与 1 个对象关联的类吗?
n----> 1
Is it safe to say that in a UML class diagram, if there is an association of n to 1 objects, then the association arrow is pointing from the class associated with n objects to the class associated with 1 object?
n ----> 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不是一般情况下。 UML 中的箭头方向对应于导航可能性。因此,如果您的箭头从 n 个对象指向 1 个对象,则意味着在生成的代码中,n 个对象中的每一个都可以访问该 1 个对象。当然,您可能还需要一个关联,其中 1 个对象可以访问 n 个对象,因此箭头指向不同的方向。 (如果没有给出箭头,则意味着 n 个对象可以访问 1 个对象,反之亦然。)
Not in general. The arrow direction in UML corresponds to navigation possiblities. Hence, if your arrow points from the n objects to the 1 object it means that in your resulting code each of the n objects can access that 1 object. Of course you may also want an association in which that 1 object can access the n objects, so the arrow points in the different direction. (If no arrowhead is given it means that the n objects can access the 1 object and vice versa.)
不完全是。这取决于协会的类型。如果它是聚合,则默认为双向导航,但您可以指定导航为单向。我认为对象之间的导航方向完全由设计者决定。
Not precisely. It depends on the type of association. If its an aggregation then the default is bi directional navigability, but you can specify the navigation to be one way. I think that it is entirely up to the designer to decide the direction of the navigation between objects.
不会。至少在面向对象编程中,具有“1”关联(OOP 中的引用)的一个类同样可以拥有对另一类的许多引用。
这取决于您所做的设计。
No. At least in object oriented programming, the one class that has the "1" association (reference in OOP) could equally well have the many references to the other class.
It depends on the design you make.
我认为箭头更多的是关于导航性(即从 A -> B 的箭头表明 A 类知道如何到达 B,但 B 不知道如何返回 A),而不是表达关系的基数。
I thought the arrow was more about navigability (i.e. an arrow from A -> B shows that class A knows how to get to B but B does not know how to get back to A) than expressing the cardinality of the relationship.
如果我可以建议的话,有 3 种不同的概念:
1 - 由箭头建模的导航能力
2 - 基数,由 0..n 的数字或星号建模
3 - 谁属于由暗点建模的关联终点
请参阅从规范中摘录的内容。
If I can suggest, there are 3 different notions:
1 - Navigability which is modeled by arrow
2 - Cardinality which is modeled by number or star for 0..n
3 - to who belongs the end point of the association which is modeled by a dark point
please see extracted from the norm.