OCL - 迭代每个项目

发布于 2024-10-29 21:30:59 字数 163 浏览 4 评论 0原文

我有一个 A 类和其他类 (B) 的集合。

如何在 OCL 中表示集合中的每个类 (B) 都对某个字段存在约束?

我想是这样的:

A.collection->iterate().field = SomeConstraint

I have a class A with a collection of other classes (B).

How do I represent in OCL that for each class (B) in the collection there's a constraint on a field ?

I thought something like:

A.collection->iterate().field = SomeConstraint

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2024-11-05 21:30:59

你的术语有点令人困惑。你的意思是你有类似的东西

A--------->* B

<前><代码> 废话

您期望 SomeConstraint 是什么?

我猜您正在 OCL 中寻找 A 类所谓的不变量

  context A
  inv allOK : bs->forall(b | ...)

更新:
如果你想计数,最简单的方法不是迭代,而是执行select(...)->count()。也许这可以简化你的问题。

Your terminology is a bit confusing. Do you mean you have something like

A--------->* B

   bs

What do you expect SomeConstraint to be?

I guess you're looking for so-called invariants in OCL for class A:

  context A
  inv allOK : bs->forall(b | ...)

Update:
If you want to count, the easiest way is not iterate, but doing select(...)->count(). Maybe that simplifies your matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文