不是聚合或组合的 UML 关联?

UML association that is not an aggregation or composition?

有人可以给出既不是聚合也不是组合的关联 UML 关系(单向箭头 ->)的代码示例吗?

我理解聚合和组合是关联的类型,但我想不出不是聚合或组合的关联关系。

下面的代码能不能只是A->B的关联关系,而不是一定条件下的聚合或组合?

import B;
public class A {
  private B b;
}

当然,只需更改您的符号所代表的内容,一个人 (A) 就可以驾驶 (b) 一辆汽车 (B),而无需组合或聚合它。

根据罗伯特·马丁的说法:

An Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.

代码:

public class A {
  private B b;
}

可以表示关联、聚合或组合。只要A和B没有"HAS-A"关系,它就代表一个单纯的关联。例如,下面可能是一个关联,但不是聚合或组合关系。

public class Vehicle {
  private Person owner;
}