A thing I have come to believe strongly, offered here for argument.
The value of OCL is not that it is formal. Plenty of notations are formal. The value is that a
correctly written constraint reads back as the sentence the domain expert said in the workshop.
Compare:
-- what people write
context Loan inv: self.a->forAll(x | x.s = 2 implies x.d <= self.l)
-- what they meant
context Loan
inv: self.advances->forAll(advance |
advance.status = Status::Approved implies
advance.amount <= self.creditLimit)
Same expression. The second one can be read aloud to the person who owns the rule, and they can
tell you whether it is right. The first one cannot, which means it will never be checked by
anyone who knows the answer.
Concretely, three habits:
- Name the iterator.
| advance |not| x |. - Never abbreviate a domain term.
creditLimit, notcl. - Break the line where the sentence breaks.
None of this affects execution. All of it affects whether the rule is correct.