钻石标志在UML类图中表示什么?[英] What does a diamond sign signify in UML class diagrams?

本文是小编为大家收集整理的关于钻石标志在UML类图中表示什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

考虑以下两个图.顶部的右端包含一个普通箭头,底部包含一个箭头,左端有钻石,右端有一个普通箭头. 很棒的书Gof 图表的种类.

我想了解钻石在第二种情况下表示什么,这两个中的哪一种在Customer和Order之间产生了更强的关联.

Customer类是在两种情况下的任何一个中都负责Order类的生命周期吗?

在此处输入图像说明 在此处输入图像说明

推荐答案

如果有没有钻石,那么我们有一个简单的关联.

如果钻石是剩下的空,则表示它是聚合.这种关系比简单的关联强.在这种情况下,客户汇总订单.

如果钻石是黑色,这意味着它是组成,它甚至比聚集更强,因为复合类别不能由其他类别组成.它的"生命"取决于容器.

我认为它的解释更为清楚,at:

其他推荐答案

客户和订单是一种" has-a"组成关系,因为如果客户不再存在,那么他/她的订单也是如此.因此,容器(客户)与该容器中的实例(订单)之间存在生命周期依赖性.当容器停止存在时,所有实例也是如此.

另一方面,如果我们说客户有一本书.在这种情况下,我们有" has-a"的聚合关系.因为如果客户停止存在,那么这本书仍然可用.

其他推荐答案

它表示聚合.来自Wikipedia:

在UML中,它以图形方式表示为空心钻石形状 包含树的类末端,并用一条线连接 包含类的类别. 在许多人中被视为单位的扩展对象 操作,尽管物理上是由几个较小的物体制成的.

http://en.wikipedia.org/wiki/wiki/class_diagram

本文地址:https://www.itbaoku.cn/post/627357.html

问题描述

Consider the below two diagrams. The top one contains a plain arrow at the right end, and the bottom one contains an arrow with a diamond at the left end and a plain arrow at the right end. The great book GoF has usages of both of these two kinds of diagrams.

I want to understand what does the diamond signify in the second case, and which one of these two gives a stronger association between Customer and Order.

Is the Customer class responsible for the lifecycle of Order class in either of the two cases?

enter image description here enter image description here

推荐答案

If there is no diamond, then we have a simple association.

If the diamond is left empty, it signifies it is an aggregation. This relation is stronger than a simple association. In this case a Customer aggregates Orders.

If the diamond is black, this means it is a composition, which is even stronger than an aggregation because the composite class cannot be composite by other classes. Its "life" depends on the container.

I think it's explained a little bit more clearly, at:

其他推荐答案

The customer and order is a "has-a" composition relationship because if the customer ceases to exist so does his/her order. Therefore, there is a life cycle dependency between the container (customer) and the instances within that container (order). When the container ceases to exist so does all its instances.

On the other hand, if we say a customer has a book. In this case, we have a "has-a" aggregation relationship. Because if the customer ceases to exist, the book is still available.

其他推荐答案

It signifies aggregation. From wikipedia:

In UML, it is graphically represented as a hollow diamond shape on the containing class end of the tree with a single line that connects the contained class to the containing class.The aggregate is semantically an extended object that is treated as a unit in many operations,although physically it is made of several lesser objects.

http://en.wikipedia.org/wiki/Class_diagram