OCL is it allow to write constraint on an operation and attribute

隐身守侯 提交于 2019-12-11 06:14:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!