You use the * operator in OCL to multiply two numeric values in calculations, derived attributes, and constraints.
Syntax
a * ba 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.
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.BonusPerEmployeeFor a department with an EmployeeCount of 10 and a BonusPerEmployee of 250, the expression evaluates to 2500.
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.BonusPerEmployeeA constraint can compare that calculated value with another numeric value:
self.EmployeeCount * self.BonusPerEmployeeThe 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.
