Search code examples
invariantsocl

OCL define invariant


If I have to define an invariant to state that the age of a person requesting a loan should be greater than 18 for the attached class diagram would this be

context Person
inv: age > 18

or

context Person
inv: self.age > 18

and what is the difference between the two?

enter image description here Thank you for your guidance


Solution

  • Both invariants in your example are exactly the same (the "self" is implicit in the first). Nevertheless, there you just say that all "person" objects must have an age value of at least 18 which is not exactly the invariant you described (in your invariant, it seemed that it was possible to have people under 18 in the system, it´s just that people under 18 could not be linked to a loan)