Associations describe structural relationships between classes that become links between the instances of these classes. These links represent inter-object navigation that is to say the fact that one instance can retrieve another instance through the navigable link.
When an association end is navigable, it means you want to be able to retrieve the instance of the class it is linked to, this instance is displayed as a migrated attribute in the current instance of a class. The rolename of this end can be used to clarify the structure used to represent the link.
For example, let us consider an association between class Company and class Person. Navigation is possible in both directions to allow Company to retrieve a list of employees, and each employee to retrieve his company.
PowerDesigner supports different ways for implementing associations in each object language.
By default, migrated attributes use the class they come from as type.
When the association multiplicity is greater than one, the type is usually an array of the class, displayed with [] signs. In our example, attribute employee in class Company is of type Person and has an array of values. When you instantiate class Company, you will have a list of employees to store for each company.
public class Company { public String Name; public String Catalog; public String Address; public Person[] employee;
Depending on the language you are working with, you may have other ways to implement migrated attributes. PowerDesigner lets you choose an implementation in the Detail tab of the association property sheet.
A container is a collection type of objects that stores elements. The container structure is more complex than the array type and provides more methods for accessing elements (test element existence, insert element in collection, and so on) and managing memory allocation dynamically.
You can select a container type from the Container Type list. This type will be used by migrated attributes. The code of a migrated attribute that uses a container type contains getter and setter functions used to define the implementation of the association. These functions are visible in the Code Preview tab, but do not appear in the list of operations.
When you use the role migration feature to visualize migrated attributes and select a container type, the generated code is identical.
Depending on the language and the libraries you are using, the container type may be associated with an implementation class. In this case, the container type is used as an interface for declaring the collection features, and the implementation class develops this collection. For example, if you select the container type java.util.Set, you should know that this collection contains no duplicate elements. You can then select an implementation class among the following: HashSet, LinkedHashSet, or TreeSet.
For more information on container types and implementation classes, see the corresponding language documentation.
The default implementation mechanism is defined in the object language resource file under the Profile\Association category. This mechanism uses templates to define the migrated attribute generated syntax, the operations to generate, and other association details. For example, template roleAMigratedAttribute allows you to recover the visibility and initial value of the association role. You can use the resource editor interface to modify implementation details.
For more information on template definition, see Customizing and Extending PowerDesigner > Customizing Generation with GTL