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. |