Search code examples
attributesumlassociationsentity-relationshipclass-diagram

When to model a multivalued attribute as a class vs a class attribute?


Is there an authoritative guidance or a commonly accepted practice as to when it is better to model a property as an associated entity/class versus as a multi-valued attribute?

For example: a person can have multiple skills. Is there a recommended practice for deciding whether it is more suitable to model a Person class associated with a Skill class or a Person class with a multivalued Skill attribute? Or would such a decision depend on the operations that can be performed or other factors?


Solution

  • The distinction in UML between an attribute, a property or an associated class is very thin and subtle:

    UML specifications (9.9.17): A Property is a StructuralFeature. A Property related by ownedAttribute to a Classifier (other than an association) represents an attribute and might also represent an association end. It relates an instance of the Classifier to a value or set of values of the type of the attribute.

    In the end, the choice is yours. But there is an unofficial rule of thumb that can help:

    • if the multivalued property has a simple type, it's usually shown as an attribute:

      enter image description here

    • if a multivalued property is of the type of class, it's usually better to show it as the end of an association with that class, unless it is a relatively simple and trivial class used in many places and that doesn't deserve so much attention:

      ![enter image description here

    • if it is a multivalued property of a type defined as «DataType», there is no generally accepted recommendation. But in principle, the attribute would reflect more intuitively the "by value" semantic, but if it is important to show that the data type is itself associated to other classes, it could be helpful to nevertheless show it as a classifier box