Reputation: 59
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 ...
Upvotes: 2
Views: 6234
Reputation: 13784
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
Upvotes: 4
Reputation: 6089
Two alternative OCL expressions can be found in the following question: Why allInstance not for isUnique?
In your case, it would be:
context Employee
inv personalNumberUnique : Employee.allInstances() -> isUnique(personalNumber)
Upvotes: 0
Reputation: 1498
You don't provide your metamodel, and clearly wrt to each Employee their personelNumber is single valued and so necessarily unique. Presumably it is within some scope such as a Company that the personelNumber should be unique, so the answer is often something like.
context Company
inv UniquePersonelNumber: employees->isUnique(personelNumber)
Upvotes: 2