我是OCL的新手,我对前后条件的工作原理有所怀疑。
可以将后置条件放在if then语句中吗?
例如,以下代码是有效的还是我只是混合概念?
Context [some context here]
if (
... some conditions...
) then (
result = 1
post: self.isComplete() -- for example
)
endif
非常感谢您的帮助
答案 0 :(得分:1)
我会把它重写为:
Context MyContext :: Integer
post :
if <some condition>
then
result = 1
endif
如果您需要更多条件,可以执行以下操作:
Context MyContext :: Integer
post :
if <some condition>
then
-- Another condition
if self.isComplete()
then
result = 1
else
result = 0
endif
else
result = 0
endif
答案 1 :(得分:0)
你可以使用如下所示的implies运算符:
context k
inv
(k.count=0)implies(k.status='nothing')