Learning UML 2.0
A.3. Operators
OCL has the basic arithmetic, logic, and comparison operators. OCL also has more advanced functions such as returning the maximum of two values and concatenating Strings. OCL is a typed language, so the operator has to make sense for its values. For example, you can't take the sum of an Integer and a Boolean. Table A-2 shows commonly used operators in OCL expressions.
Operators in the groups Comparison, Equality, and Boolean all return results of type Boolean. For example, age = 65 evaluates to true or false. The other operators in Table A-2 return the same type with which they're used. For example, if baseCost and tax are Real, then baseCost + tax will also be Real. Figure A-2 shows that getTaxRate( ) returns a double (this model was written with Java types), but the table in Table A-2 mentions that the operator + is defined on Reals and Integers. That's perfectly fine; when building an OCL expression, you can match your types to the closest OCL type.
|
Категории