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

The > operator lets you write OCL conditions that are true only when one comparable value is strictly greater than another; use it in constraints, validations, and conditional expressions.

Syntax

leftValue > rightValue

The expression returns a Boolean value:

Condition Result
leftValue is greater than rightValue true
leftValue is equal to or less than rightValue false

Both operands must be comparable. The operator is defined as > ( object : T ) : Boolean: it returns true when the value on the left is comparable to, and greater than, the value on the right. See Documentation:Mathematical symbols for the mathematical-operator definitions.

Compare an attribute with a value

For a Department with an EmployeeCount attribute, require that the department has at least one employee:

self.EmployeeCount > 0
EmployeeCount Expression result Meaning
0 false The department has no employees.
1 true The department has more than zero employees.
12 true The department has more than zero employees.

Assume the Department class has an attribute called EmployeeCount.

self.EmployeeCount > 0

The department must have more than zero employees. If EmployeeCount is greater than 0, the expression returns true, else it returns false.

Use in an invariant

An invariant is a condition that instances of a class must satisfy. Put the comparison in the context of the class whose attribute you are checking:

context Department inv:
  self.EmployeeCount > 0

This invariant evaluates to true for a department with one or more employees and false for a department whose EmployeeCount is zero.

Strict comparison

> is a strict comparison: equal values do not satisfy it. For example:

self.EmployeeCount > 5
EmployeeCount Result
5 false
6 true

If the boundary value must also be accepted, use greater than or equal to (>=) instead. For example, self.EmployeeCount >= 5 returns true when EmployeeCount is exactly 5.

Combine comparisons

Use and when both conditions must be true. This example accepts a department only when its employee count is greater than zero and its budget is greater than zero:

(self.EmployeeCount > 0) and (self.Budget > 0)

Use or when either condition is sufficient. For example:

(self.EmployeeCount > 10) or self.IsStrategic

This expression is true when the department has more than ten employees, when IsStrategic is true, or when both conditions are true.

The operator also works with collections using OCL navigation: Using the greater than operator on collection

Department.allInstances->exists(d | d.EmployeeCount > 10)

Results:

See also