时间:2006-12-29 关键字: OO UML,泛化,依赖,关联,聚合
看了Qualified Associations的定义,现在总结下对这个关系的理解。不对之处敬请指出。
首先看下UML distilled third对它的定义
Qualified Associations
A qualified association is the UML equivalent of a programming concept variously known as associative arrays, maps, hashes, and dictionaries. Figure 5.10 shows a way that uses a qualifier to represent the association between the Order and Order Line classes. The qualifier says that in connection with an Order, there may be one Order Line for each instance of Product.

From a software perspective, this qualified association would imply an interface along the lines of
class Order ...
public OrderLine getLineItem(Product aProduct);
public void addLineItem(Number amount, Product forProduct);
Thus, all access to a given Order Line requires a Product as an argument, suggesting an implementation using a key and value data structure.
It's common for people to get confused about the multiplicities of a qualified association. In Figure 5.10, an Order may have many Line Items, but the multiplicity of the qualified association is the multiplicity in the context of the qualifier. So the diagram says that an Order has 0..1 Line Items per Product. A multiplicity of 1 would indicate that Order would have to have a Line Item for every instance of Product. A * would indicate that you would have multiple Line Items per Product but that access to the Line Items is indexed by Product.
In conceptual modeling, I use the qualifier construct only to show constraints along the lines of "single Order Line per Product on Order."
|
就是说在Order和Order Line之间的Association关系之外,再定义它们之间的一个关键object.从代码上说,就是用户想从Order得到一个OrderLine的话,他必须还需提供一个Product作为参数才可以。当然order->(*) Order Line(Order是一对多个orderLine时),就是用户想从order得到多个Order Line时,他必须提供一个Product作为参数。
[代码表现为]
java 代码
- class Order ...
- public List getLineItem(Product aProduct);