2

If class A has many of class B and class B has many of class A, should we place a diamond on both sides of the line between them?

Like in the picture below, or is it fine to just indicate the amount in both directions and have the diamond only on one side?

enter image description here

3
  • I think you should give a concrete example unless your question is purely theoretical. Two way aggregation is not a common concept and having references going both ways is often a bad idea.
    – COME FROM
    Aug 24 '16 at 10:27
  • For example a car has several tires and a tire has 0 or one car.
    – shinzou
    Aug 24 '16 at 13:16
  • 1
    I don't think it's very common to consider tires "having" a car. The relationship between a car and it's parts or components is a typical text book example of a normal one way aggregation or composition.
    – COME FROM
    Aug 25 '16 at 6:17
2

Simple answer is: no. You can't have diamonds on both ends of the same line.

Aggregation is a whole/part relationship (having diamond on a whole side). A single association represents a particular relationship between instances of a class and thus the same object cannot be simultaneously a part of other object and a whole containing the same object. While hard to imagine and bringing other problems on table one could try to build such construct, where object of type A is build of objects B and object of type B is build of objects of type A (the only examples that come to my mind at the moment are some math structures) but this would be anyway two different relationships (so two different lines connecting the same classes A and B but each of the lines having the diamond on different class end).

In your example the tyre is a part of (at most one) car so the diamond will be on car side. If you want to show navigability from a tyre to a car (i.e. tyre "knows" to which car it is connected) use the arrow in the car direction just before the diamond. Plus use multiplicity of course (the multiplicity at whole part can be zero.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.