2.8 Let Expressions


Sometimes one writes large expressions in which a sub-expression is used more than once. The let expression enables you to define a variable that can be used instead of the sub-expression. The following example states that either the validFrom or the goodThru date of a customer card needs to be adjusted when the card is invalidated. An extra variable named correctDate is defined to indicate whether or not the current date is between the validFrom and goodThru dates:

 c  ontext  CustomerCard  inv  :  let  correctDate : Boolean =                   self.validFrom.isBefore(Date::now) and                   self.goodThru.isAfter(Date::now)  in  if valid then            correctDate = false         else            correctDate = true         endif 

A let expression may be included in any kind of OCL expression. The newly defined variable is known only within this specific expression.



Object Constraint Language, The. Getting Your Models Ready for MDA
The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)
ISBN: 0321179366
EAN: 2147483647
Year: 2003
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net