1

How do I represent an aggregation relation between two classes in UML, such that each class has a link to the other class's interface, not the implementing class?

E.g. I have a class Foo that implements iFoo, and Bar that implements iBar. Foo should have a member variable of type iBar, and Bar should have a member variable of type iFoo.

If I create an aggregation between the two implementing classes, then the member will be of the type of the implementing class, not the superclass. And aggregations between interfaces are invalid in UML (and don't make much sense).

4

2 回答 2

1

接口不可实例化,因此 Bar 不能具有 iFoo 类型的属性,而 Foo 不能具有 iBar 类型的属性。

你说你不想要 Bar 和 Foo 之间的关联。因此,您可以创建一个新类 (FooEx) 并让该类实现 iFoo。然后 Bar 可以与 FooEx 而不是 Foo 建立关联。

于 2008-09-19T04:20:10.447 回答
1

你能不能没有 Foo(实现)聚合 iBar(接口)?在我看来,这似乎是描述这种关系的正确方式。

所以是这样的:

-----------------      -----------------
| <<interface>> |      | <<interface>> |
|     iFoo      |<>  <>|     iBar      |
-----------------  \/  -----------------
        ^          /\          ^
        |         /  \         |
-----------------/    \-----------------
|      Foo      |      |      Bar      |
-----------------      -----------------
于 2008-09-18T16:05:49.510 回答