One-to-Many Aggregation

In this example a one-to-many aggregation is modeled, meaning that a list of one class type is embedded into the other class. Here we create PersonDetailsList, which aggregates a list of PersonDetails. To create a one-to-many aggregation, open an Rational Software Architect diagram and do the following:

This creates the aggregation relationship whereby one role corresponds to class PersonDetailsList and the other to class PersonDetails.

Note: The position of the diamond is important as it denotes the outermost class in the pair.

With the relationship line selected in the diagram the General Properties tab should show PersonDetailsList in the graphic at the top of the properties sheet with the diamond associated with it.

Set the following properties of the aggregation:

The class diagram would appear in the Rational Software Architect showing the two classes joined by the UML aggregation relationship line (diamond end touching PersonDetailsList) and the aggregates side of the relationship showing a multiplicity of * and PersonDetails showing a multiplicity of 1..* and a role name of - dtls.

The pseudo-code resulting from this construct would take the following format:

struct PersonDetails implements
java.io.Serializable, curam.util.type.DeepCloneable {

  String personRefNo = "";
  String firstName = "";
};

struct PersonDetailsList implements
java.io.Serializable, curam.util.type.DeepCloneable {

  public static class List_dtls
  extends curam.util.type.ValueList {
    public void addRef(PersonDetails s) {
      add(s);
    }
    public PersonDetails item(final int indx) {
      return (PersonDetails) get(indx);
    }
    public PersonDetails[] items() {
      PersonDetails[] result = new PersonDetails[size()];
      toArray(result);
      return result;
    }
  }

  // This class contains an embedded list of "PersonDetails":
  public final List_dtls dtls = new List_dtls();

}

The resulting generated struct class for PersonDetailsList has a field named dtls which provides functionality required for lists such as adding items, getting an item by index and getting the list contents as an array.