One-to-many aggregation
One-to-many aggregation embeds a sequence of one class within many others.
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:
- Add classes PersonDetails and PersonDetailsList to the diagram;
- In the diagram drag the appropriate arrowhead (it appears when the mouse cursor is hovering over the class) between the two classes with PersonDetailsList as the source and PersonDetails as the target;
- Select Create Aggregation from the popup menu;
- With the aggregation relationship selected in the diagram open the General Properties tab.
This creates the aggregation relationship whereby one role corresponds to class PersonDetailsList and the other to class PersonDetails.
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 Label is optional;
- For PersonDetailsList:
- The Aggregation radio button should indicate Composite;
- Multiplicity should be set to *;
- For PersonDetails:
- The Aggregation radio button should indicate None;
- By default the role is set to "dtls";
- Multiplicity should be set to 1..* (to signify a one-to-many 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.