🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators Or
This page was created by Stephanie on 2023-04-20. Last edited by Wikiadmin on 2026-07-29.

You use the OCL or operator to make a condition succeed when at least one Boolean condition is true; it is for MDriven users writing OCL expressions in constraints, validations, and other Boolean rules.

Syntax

conditionA or conditionB

Both operands must evaluate to a Boolean value: true or false. The whole expression evaluates to true when either operand, or both operands, is true.

conditionA conditionB conditionA or conditionB
false false false
false true true
true false true
true true true

Use or to express alternatives

Use or when an object is valid if it meets one of several alternative conditions.

For example, a Person is eligible when the person is at least 18 years old or has a driver's licence:

(self.age >= 18) or self.hasDriverLicense

The expression is true for a person aged 18 without a licence, for a younger person with a licence, and for a person who meets both conditions. It is false only when neither condition is met.

Example: match either of two categories

To test whether the current Product belongs to either accepted category, use one comparison for each category:

(self.category = 'Electronics') or (self.category = 'Books')

Use this Boolean expression where a Boolean result is required. For example, it can be the condition of a validation that accepts products in either category.

Group each condition

Put parentheses around each comparison or larger Boolean condition. This makes the alternatives clear and prevents a reader from confusing the comparison with the Boolean operation.

For example, write:

(self.age >= 18) or self.hasDriverLicense

rather than relying on the reader to infer how a longer expression is grouped.

When all conditions must be true, use the corresponding Boolean operator described in OCL Boolean Operators.

See also