Target models for OCL statements

When you write Object Constraint Language (OCL) statements, the target model determines which features of the context element your OCL statements can access. The target model can be either the user model or the metamodel.

User model

When you specify the target model as the user model, you limit your OCL statements to the user-defined features of the context element. Also, when you specify the target model as the user model, you cannot evaluate OCL statements. You can only parse OCL statements to ensure that they are syntactically valid.

For example, if you specify the target model as the user model, and you select a class or an interface as your context element, your OCL statements are limited to the following attributes and operations:
  • Attributes that the class or interface define
  • Specific OCL-defined operations, such as oclIsType()

Metamodel

When you specify the target model as the metamodel, your OCL statements have access to the metamodel features of the context element, and any features that stereotypes applied to the context element contribute. Also, when the target model is the metamodel, you can parse OCL statements to see if they are syntactically valid, as well as evaluate the output from them.

For example, if you specify the target model as the metamodel, your OCL statements can access the following features:
  • All the attributes that are defined in the metaclass that represents the context element
  • Attributes that are defined in stereotypes that are applied to the context element
  • All the OCL-defined methods

Feedback