🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators less than
This page was created by Charles on 2025-11-18. Last edited by Wikiadmin on 2026-07-29.

You use the < operator in OCL expressions to test whether one comparable value is strictly less than another; it is for anyone writing constraints, validations, or conditional expressions in MDriven.

Syntax

leftValue < rightValue

The expression returns a Boolean value:

  • true when leftValue is less than rightValue.
  • false when leftValue is equal to or greater than rightValue.

Both operands must be comparable. The mathematical symbols reference defines < as returning true when self is comparable to, and less than, the value on the right.

Compare an attribute to a value

For a Department class with an EmployeeCount attribute, use the following expression to test whether the department has fewer than 10 employees:

self.EmployeeCount < 10
EmployeeCount Result Meaning
9 true The department has fewer than 10 employees.
10 false 10 is not less than 10.
12 false The department has more than 10 employees.

For example, use this expression as an invariant when every Department must contain fewer than 10 employees:

context Department inv: self.EmployeeCount < 10

Strict comparison

The < operator excludes the limit value. If 10 employees is allowed, use less than or equal to (<=) instead:

self.EmployeeCount <= 10
Requirement Operator Example
Fewer than 10 employees; 10 is not allowed. < self.EmployeeCount < 10
At most 10 employees; 10 is allowed. <= self.EmployeeCount <= 10

Use in conditional expressions

You can use the Boolean result wherever an OCL expression expects a condition. For example, the following evaluates whether a person is below an age threshold:

self.Age < 18

This expression returns true for an age of 17 and false for an age of 18.

Related comparisons

See also