我不确定我是否使用 association and aggregation or composition diamond适本地。
我会将 Association 用于接口(interface),因为我无法实例化它们。就像他们这样做 here例如。或者对于静态类,同样的原因。
而我只用于我可以实例化的对象的菱形。和普通类一样。
但我不确定这是否是区分它们的正确方法,因为如果您 check再一次,你会看到他们对此并不那么具体。在 UML 2.3 specification我不能出去更多,所以你是怎么使用它的?
还有第三种方式,虚线 <> 箭头,但我没有胶水什么时候使用这个。所以也许你也可以帮我解决这个问题?
最佳答案
I would use the Association for interfaces, because I can't instantiate them. Like they do it here for example. Or for static classes, same reason.
And the diamonds I use only for objects I can instantiate. Like normal classes.
这不是他们真正的工作方式。三种形式(关联、聚合和组合)定义了关系的不同属性。这三个通常在类之间使用,尽管也可以关联接口(interface)。关联和组合是最简单的两个:
聚合(未填充的菱形)位于中间的某个位置。它有点像组合 - 除了它不要求上述属性。我个人不使用它。语义太不清楚了,不值得。
And there is a third manner, the dashed lined <> arrow, but I don't have a glue when to use this one.
我认为你的意思是依赖关系。这是一种较弱的关联形式。举个例子,下面的类定义
class Foo {
def bar(Baz: aParam) {
...
}
}
在这种情况下,类型 Foo 依赖于类型 Baz,因为它在 bar() 方法签名中的使用。但是它们之间没有关联(不能明智地讨论例如 Foo 实例和 Baz 实例之间关系的基数)。从实际的角度来看,我会说:
hth。
关于UML 类图 Association vs ( Aggregation | Composition )-Diamonds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7834052/