Generating Associations

The testdata project on SourceForge represented an association between two classes as an XML element, which contained two elements that represented the association ends. This XML was used to configure an algorithm, presented here, that generated instances of the associated classes.

We use the following definitions:

  • Multiplicity is an integer-valued function that is attached to an association end at design-time, that describes the number of class instances to generate at runtime.
  • Cardinality is an integer value attached to an association end at runtime, that describes the number of class instances to generate for the current generation.
  • Two instances are correlated if they're generated by classes that are associated. Two associated classes can generate many correlated instances in one generation.

We'll use some constraints:

  • An integral number of instances should be generated. For example, if the ratio of A to B is 2:3, it is not reasonable to generate 1 value for A and 3/2 value for B.
  • A minimal number of instances should be generated. Using the above example, we could generate {2A,3B}, {4A,6B}, {6A,9B}, ... We choose to generate {2A,3B} by default, and provide the capability to generate multiples.

It would also be nice if, given a set of associations, the number of instances we end up with are independent of the order in which we iterate through the association ends.