不了解关系之间的区别

发布于 2025-02-12 14:47:24 字数 802 浏览 1 评论 0原文

在这里,我有此类图:

”在此处输入图像描述

这是我不理解的事情:

  1. 为什么order - OrderDetail聚合?不应该只是关联,因为它将具有list< orderdetail>喜欢:
public Order{
    public DateTime date;
    public Status status;
    public List<OrderDetail> orderDetails;
}
  1. 为什么orderdetail - item item a的依赖关系?它不应该是关联,因为它有对该item类的引用?

图的参考: http://ssslabmcs12.weeebly.com/Resources/Resources1.html

Here I have this class diagram:

enter image description here

Here are the things that I don't understand:

  1. Why is Order - OrderDetail an aggregation? Shouldn't it just be an association, since it will have a List<OrderDetail> like:
public Order{
    public DateTime date;
    public Status status;
    public List<OrderDetail> orderDetails;
}
  1. Why is OrderDetail - Item a dependency? Shouldn't it be association since it has a reference to that Item class?

Reference for the diagram:
http://sslabmcs12.weebly.com/resources1.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心旳酸楚 2025-02-19 14:47:24
  1. 是的,A 简单关联将是正确的选择。无论如何,这是一个共享聚合,它没有定义的语义。参见p。 UML 2.5的110:

表示该属性已共享聚合语义。共享聚合的精确语义因应用区域和建模者而异。

因此,您最好询问图表作者有关他的意图。

  1. 这不是依赖性,而是关联。依赖性将用虚线呈现。导航性(使您认为这是一种依赖性的箭头权利)是少量用途。它表明OrderDetail可以看到item,但反之亦然。最好仅在一侧使用角色名称来表达这一事实。例如,仅在右侧放置item,而左侧没有任何内容。

我们能学到什么? UML是关于沟通的!

  1. Yes, a simple association would be the right choice. Anyhow, this is a shared aggregation which has no defined semantics. See p. 110 of UML 2.5:

Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.

So you best ask the diagram author about his intentions.

  1. It's not a dependency but an association. A dependency would be rendered with a dashed line. The navigability (the arrow right which made you belief it's a dependency) however is of minor use. It indicates that OrderDetail can see Item but not vice versa. A fact that could better be expressed by using role names only at one side. E.g. placing item only on the right hand side and nothing to the left.

What can we learn? UML is about communication!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文