In UML models, a constraint is an extension mechanism that lets you refine the semantics of a UML model element. A constraint refines a model element by expressing a condition or a restriction in a textual statement to which the model element must conform.
An example of a constraint is a condition such as {count > 10}. A constraint must be enforced in the design of a system. You specify the condition or restriction in the body of the constraint.
Typically, constraints do not have names. Instead, they are identified by the contents of their bodies. Some commonly used constraints are identified by names so that the contents of their bodies do not have to be repeated. The XOR constraint is applied when more than one association has a common connection to one class.
For more information about OCL, read the Unified Modeling Language specification that is available on the Object Management Group (OMG) Web site. In general, syntax for the body or body language properties is not enforced.
A constraint is displayed as text enclosed in braces ({}) and appears in a rectangle with a folded upper-right corner.
You can add constraints to your model for the following purposes:
In models that depict software systems, constraints represent conditions or restrictions that you can find no other way to model.
In model that depict time-critical software systems, constraints provide a statement about the relative or absolute value of time during an interaction.
The constraints in a model can appear in any type of UML diagram as well as free-form diagrams.
You can validate a constraint. The level of validation of constraint that takes place depends on the type of constraint being validated. There are the following three types of constraints:
The syntax and the expression of a constraint are validated if the constraint has the «metaConstraint» stereotype applied to it or is defined in a profile.
Only the syntax of a constraint is validated if it does not have the «metaConstraint» stereotype applied to it and it is not defined in a profile.
Related tasks
Applying constraints to model elements
Validating OCL constraints
Specifying bodies for the constraints of model elements
Specifying body language for the constraints of model elements
Modeling user workflow by using activity diagrams
Specifying the flow of control and data in activity diagrams
Grouping the behaviors in activities