Several Associations

What happens when more than two classes are associated? Figure 2 shows four associated classes. A, C, and D each have one association, and B has three.

Figure 2: Several Associated Classes

Again, how many instances of each class should we generate with each generation? As in the previous example, assume cardinalities equal to maximum multiplicities. Then

  • For each 2A we need 3B (2A = 3B)
  • For each 2B we need 3C (2B = 3C)
  • For each 3B we need 5D (3B = 5D)

How many values of each class should we generate with each generation? In particular, how many of B should we generate, since it participates in several associations? If we generate 3 values of B, then we're all set with A and D (we'd generate 2A and 5D). But we'd need 41/2 of C, which violates the integral number of values constraint. Similarly, if we generated just 2B, then C would be satisfied, but A and D would not. We need to find new values such that the original ratios are maintained, but an integral number of values are generated. For each end, we call this new value the size of the end, to distinguish it from the original cardinality.

We want to combine the three statements in the example into one, whose sizes give the number of values we need. To do this, we:

1. Find the class that has more than one association (here, B).
2. Find the cardinalities of its ends. From above, these values are B[3], B[2], and B[3].
3. Find the least common multiple (LCM) of these cardinalities. Here, LCM(3,2,3)=6. This becomes B's size.
4. Update the sizes of the other classes, by multiplying B's size by the ratio of cardinalities. For example: A[2]=B[3], so size(A)=size(B)*2/3. Then size(A)=6*2/3=4. Similarly:
  • size(A) = 2*6/3 = 4
  • size(B) = 6
  • size(C) = 3*6/2 = 9
  • size(D) = 5*6/3 = 10

The number of instances at each end is just the size of that end: 4A, 6B, 9C, 10D.