OCL对类A的操作和类B的属性的写约束 [英] OCL write constraint on an operation of class A and attribute of class B
本文介绍了OCL对类A的操作和类B的属性的写约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关注另一篇文章:
我想知道OCL是否允许以下操作.
I would like to know if OCL allows the following.
想象一下下面的UML图.
Imagine the following UML diagram.
如何使用ocl建模:只有当他来自国家名称'ABCD'且该国家的人口> = 1000000时,他才能喝Water()"
How to use ocl to model: "a person can drinkWater() only if he is from country name 'ABCD'" AND if the population of the country is >= 1000000"
当然,这个例子纯粹是虚构的.
Of course, the example is purely fictive.
================ ================
| Person | | Country |
|--------------| |--------------|
|- name |------------------|- id |
|- age | |- name |
|--------------| |- population |
|+ drinkWater()| ================
|+ drinkBeer() |
================
推荐答案
您将需要命名Country
的角色(在Person
中创建一个命名属性).因此,我们将其命名为country
.当然可以照常使用":
You will need to name the role of Country
(create a named attribute inside Person
). So let's name that country
. This of course can be used "as usual":
context Person::drinkWater()
pre Enough: self.country.name == "ABCD" and self.country.population >= 1000000
这篇关于OCL对类A的操作和类B的属性的写约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文