Definition

A definition constraint is a constraint that is linked to a Classifier. It may only consist of one or more LetExps. The variable or function defined by the Let expression can be used in an identical way as an attribute or operation of the Classifier. Their visibility is equal to that of a public attribute or operation. The purpose of a definition constraint is to define reusable sub-expressions for use in other OCL expressions.

The placement of a definition constraint in the UML metamodel is shown in Figure 30. The following well-formedness rule must hold. This rule also defines the value of the contextual Classifier.
 

Well-formedness rules

[1] The ExpressinInOcl is a definition constraint if it has the stereotype <<definition>> (A) and the constraint is attached to only one model element (B) and the constraint is attached to a Classifier (C).

context ExpressionInOcl
def: isDefinitionConstraint : Boolean =
    self.constraint.stereotype.name = 'definition' -- A
    and
    self.constraint.constrainedElement->size() = 1 -- B
    and
    self.constraint.constrainedElement.any(true).oclIsKindOf(Classifier) -- C
 


[2] For a definition constraint the contextual classifier is the constrained element.

context ExpressionInOcl
inv: isDefinitionConstraint implies
    contextualClassifier =
        self.constraint.constrainedElement.any(true).oclAsType(Classifier)

[3] Inside a definition constraint the use of @pre is not allowed.

context ExpressionInOcl
inv: --