我知道依赖“使用a”和继承“is-a”,但我有点不熟悉聚合,组合,关联和直接关联;也有,他们是“有-a”关系。一些使用聚合与协会可互换。
什么是直接关联?另外,什么是组合?在UML图中,表示它们的箭头是不同的。我会真的感谢,如果你能为我清除这些事情。
临时关联
A usage inside a method,its signature or as a return value. It’s not really a reference to a specific object.
例如:我把车停在车库里。
组成关联
A so-called “STRONG relationship“: The instantiation of the linked object is often hard
coded inside the constructor of the object. It cannot be set from
outside the object. (Composition cannot be a many-to-many
relationship.)
示例:房子由石头组成。
直接关联
This is a “WEAK relationships“. The objects can live independent and there are usually setters or other ways to inject the dependent objects.
示例:汽车可以有乘客。
聚合关联
Very similar to a Direct association. It’s also a “WEAK relationship” with independent objects. However here the associated objects are a crucial part of the containing object.
示例:汽车应该有轮胎。
注意:直接关联和聚合关联通常被概括为“关联”。区别是微妙的。