问题
Imagine the following class Person
================
| Person |
|--------------|
|- name |
|- age |
|--------------|
|+ drinkWater()|
|+ drinkBeer() |
================
Using OCL, is it possible to set a constraint on the operation drinkBeer()
? For instance allowing only Person >= 21 year old to drink beer?
回答1:
context Person::drinkBeer()
pre Adult: self.age >= 21
should probably do.
来源:https://stackoverflow.com/questions/43815870/ocl-is-it-allow-to-write-constraint-on-an-operation-and-attribute