OCL是否允许对操作和属性写约束 [英] OCL is it allow to write constraint on an operation and attribute
本文介绍了OCL是否允许对操作和属性写约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象一下下面的类Person
Imagine the following class Person
================
| Person |
|--------------|
|- name |
|- age |
|--------------|
|+ drinkWater()|
|+ drinkBeer() |
================
使用OCL,是否可以对操作drinkBeer()
设置约束?例如,只允许21岁以上的人喝啤酒?
Using OCL, is it possible to set a constraint on the operation drinkBeer()
? For instance allowing only Person >= 21 year old to drink beer?
推荐答案
context Person::drinkBeer()
pre Adult: self.age >= 21
应该可以.
这篇关于OCL是否允许对操作和属性写约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文