umlclass-diagramocl

How to specify the unique identifier of a Class


I have to indicate for the Employee class that each employee can be clearly identified by his personal number. I do not know if I think too complicated, because I have no real idea.

Attributes: final int personelNumber ...


Solution

  • You don't even need an OCL constraint to express that in UML. There is a property isID on the Property metaclass that ensures this:

    From UML 2.5 specification § 9.5.3 (p. 111)

    A Property may be marked, via the property isID, as being (part of) the identifier (if any) for Classifiers of which it is a member. The interpretation of this is left open but this could be mapped to implementations such as primary keys for relational database tables or ID attributes in XML. If multiple Properties are marked as isID (possibly in generalizing Classifiers) then it is the combination of the (Property, value) tuples that will logically provide the uniqueness for any instance. Hence there is no need for any specification of order and it is possible for some of the Property values to be empty. If the Property is multivalued then all values are included.

    The notation for this property is similar to that of other constraints using {id} after the name and type of the attribute

    enter image description here