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

You use the * operator in OCL to multiply two numeric values in calculations, derived attributes, and constraints.

Syntax

a * b

a is the first numeric factor and b is the second numeric factor.

The expression returns a numeric value. The result is an Integer or Real, depending on the operands.

Basic Syntax

a * b

a is the first factor

Multiply attribute values

For example, assume that a Department has these attributes:

Attribute Type Meaning
EmployeeCount Integer The number of employees in the department.
BonusPerEmployee Double The bonus assigned to each employee.

Use multiplication to calculate the department's total bonus:

self.EmployeeCount * self.BonusPerEmployee

For a department with an EmployeeCount of 10 and a BonusPerEmployee of 250, the expression evaluates to 2500.

Calculate total Total Bonus

self.EmployeeCount * self.BonusPerEmployee

Using Multiplication with a collection

Use multiplication in expressions

Use * wherever an OCL expression must calculate a value from two numeric expressions. For example, a derived value can use the same expression:

self.EmployeeCount * self.BonusPerEmployee

A constraint can compare that calculated value with another numeric value:

self.EmployeeCount * self.BonusPerEmployee

The comparison operator and limit must be defined for the constraint you are creating.

Collection operands

This page documents multiplication of two numeric values. Do not assume that * multiplies a collection directly; use an expression that produces the required numeric values before applying the operator.

For example, use multiplication within a collection operation:

Department.allInstances
  ->collect(d | d.EmployeeCount * d.BonusPerEmployee)

See also