Basic OCL Elements
Expressions, Types, and Values
Types in OCL are divided into the following groups:Basic Types and Operators
The Boolean Type
Example: The result of the following sample expression is true if for every service it can be said that when it offers bonus points it never burns bonus points
context Service
inv: self.pointsEarned > 0 implies not (self.pointsBurned = 0)
Another interesting operation on the Boolean type is the if-then-elseif ‹boolean OCL expression›
then ‹OCL expression›
else ‹OCL expression›
endif
The Integer and Real Types
All these examples are expressions of the Boolean type, which result in true:
The String Types
All these examples are expressions of the Boolean type, and result in true:
Precedence Rules
Comments
An OCL line comment begins with two hyphens. All text from the hyphens to the end of the line is considered to be a comment. Comments longer than one line may be enclosed between /* and */.
All these examples are expressions of the Boolean type, which result in true:
2654 * 4.3 + 101 = 11513.2
(3.2).floor() / 3 = 1
1.175 * (-8.9).abs() - 10 = 0.4575
12 > 22.7 = false
12.max(33) = 33
33.max(12) = 33
13.mod(2) = 1
13.div(2) = 6
33.7.min(12) = 12.0
-24.abs() = 24
(-2.4).floor() = -3
The String Types
All these examples are expressions of the Boolean type, and result in true:
'Anneke'.size() = 6
('Anneke' = 'Jos') = false
'Anneke '.concat('and Jos') = 'Anneke and Jos'
'Anneke'.toUpper() = 'ANNEKE'
'Anneke'.toLower() = 'anneke'
'Anneke and Jos'.substring(12, 14) = 'Jos'
Precedence Rules
Comments
An OCL line comment begins with two hyphens. All text from the hyphens to the end of the line is considered to be a comment. Comments longer than one line may be enclosed between /* and */.
-- the expression 20 * 5 + 4 should be evaluated here
20 * 5 + 4 -- this is a comment
/* this is a very long comment that does not enlighten the reader one bit about what the expression is really about */
20 * -- this is a comment 5 + 4 (invalid OCL expression)
0 意見:
張貼留言