Skip to content

Attribute or association

Knut Jetlund edited this page May 19, 2016 · 4 revisions

Home Modelling

Short version: Use associations for classes and attributes for data types

This page is inspired by Geert Bellkeens' blog post Attribute or Association. See also this article on classes and data types.

UML and the General Feature Model in ISO19109 has two similar ways of providing characteristics to an object: Attributes and associations. The simple approach for characteristics of an object is attributes with the primitive data types from ISO19103 (Integer, CharacterString etc). But attributes can also have complex data types with several attributes of their own, for instance the classes and data types fro Citation from ISO19115 Metadata are widely used as characteristics of classes in other standards. The question in such cases is often when to use attributes with complex data types, and when to use associations.

In the General Feature Model, attributes and associations are both based on the metaclass PropertyType, and they are in many ways equivalent. As described in Geert Beelkens blog post, they are also based on the same mechanisms in the UML meta model, and will look quite similar in an implementation (associations will look like attributes in GML).

Furthermore, according to the UML specification, "A data type is a special kind of classifier, similar to a class. It differs from a class in that instances of a data type are identified only by their value". In other words, an instance of a data type is not an object that exists on its own, and it will always have to be a part of the related object in implementations.

The basic rule to follow is to look at what kind of classifier the characteristic is based on. Is it a data type or a feature type? If it is a feature type it may exist outside of the main feature, and it should only be refered to with an association.

On the other hand, it the classifier is a data type (even after applying the rules in this article), the values of the data type will follow the main feature wehther it is based on an association or an attribute. And as mentioned above, it will appear very similar to an attribute in GML. Therefore, for characteristics based on data types, prefer to use attributes.

Also remember that based on the same principles, a simple association to a data type does not make sence, it must be a composition. This is stated in requirement 12 in ISO19103 as well.

You can’t perform that action at this time.