views:

809

answers:

2

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).

+1  A: 

Can you not have Foo (implementation) aggregate iBar (interface)? That seems to me the proper way to describe this relationship.

So something like this:

-----------------      -----------------
| <<interface>> |      | <<interface>> |
|     iFoo      |<>  <>|     iBar      |
-----------------  \/  -----------------
        ^          /\          ^
        |         /  \         |
-----------------/    \-----------------
|      Foo      |      |      Bar      |
-----------------      -----------------
jdmichal
It looks like aggregation markers are placed on the wrong ends of associations... Other than that, this diagram depicts exactly what was required.
Yarik
A: 

Interfaces are not instantiable, so Bar cannot have an attribute of type iFoo, and Foo cannot have an attribute of type iBar.

You say you don't want an Association between Bar and Foo. So you could create a new Class (FooEx) and have that Class implement iFoo. Then Bar can have an Association to FooEx instead of Foo.

chimp