To create an object constraint and link it with the context:
- In the Class/package diagram Tool Palette, choose the Constraint button and click the diagram background. The note element appears with the OCL editor activated.
- Type the constraint expression.
- Close the OCL editor.
- In the diagram Tool Palette, choose the button, and link the constraint node with the respective design element.
Tip: The constrained attribute should actually exist in the context. Otherwise the constraint will be marked as invalid.
Alternatively, follow these steps:
- In the Model View or in the diagram, right-click an element for which a constraint should be created.
- Choose Constraints.
- In the Add / Remove constraints dialog box, click Add.
- Enter the constraint:
- In the Name field, enter the constraint name.
- In the Language field, choose OCL or text from the list box.
- In the Constraint field, enter the constraint text.
- Add as many constrains as needed.
- Click OK when ready.