有谁知道好的对象约束语言(OCL)教程吗?

发布于 2024-07-21 21:18:15 字数 622 浏览 3 评论 0原文

我遇到了几个关于 OCL 表达式的问题。 在阅读了一些大学幻灯片并通过谷歌搜索后,我仍然无法正确理解它。

我想知道你们中是否有人知道我应该阅读哪些好的资源来理解这些东西。


困扰我的限制是:

  1. 该部门的每个人都有同一个经理。
  2. 公司里没有人是他/她自己的经理。
  3. 公司里没有人比他的经理挣得更多。

对于第一个,我有:

context Department

inv self.stuff -> forAll(manager = self.staff.manager)

第二个:

context Company

inv self.employee -> 选择(经理=经理.经理)-> isEmpty()

第三个:

context Company

inv self.employee -> select(工资>经理.工资)-> isEmpty()

但我认为这些不对。 我最不确定的是,在示例 2 和 3 中,我是否真的将个别员工与他们的实际经理/经理工资进行了比较。

I came across couple of questions about OCL expressions. After reading some university slides and googling it I still cannot properly understand it.

I wonder if any of you guys know any good resources that I should read to understand this stuff.


Constraints that bother me:

  1. Everybody working in the department has the same manager.
  2. Nobody in the company is the manager of him/herself.
  3. Nobody in the company earns more than his manager.

For the 1st one I have:

context Department

inv self.stuff -> forAll(manager = self.staff.manager)

2nd one:

context Company

inv self.employee -> select(manager = manager.manager) -> isEmpty()

3rd one:

context Company

inv self.employee -> select(salary > manager.salary) -> isEmpty()

but I dont think these are right. What I'm most unsure of is whether in example 2 and 3 I actually compare individual employees with theirs actual manager / manager salary.

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

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

发布评论

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

评论(4

得不到的就毁灭 2024-07-28 21:18:15

终于有好东西了!

这是来自对象管理组 (OMG) 的内容非常丰富的文档 (PDF):

对象约束语言规范

我喜欢回答我自己的问题:)

Finally got something good!

This is very informative document (PDF) from Object Management Group (OMG):

Object Constraint Language Specification

I love answering my own questions :)

风筝有风,海豚有海 2024-07-28 21:18:15

@Artur 发布的 PDF 文件的链接已更改,这是新链接
http://www.omg.org/spec/OCL/2.0/PDF/< /a>

The link to PDF file posted by @Artur has changed, Here is new link
http://www.omg.org/spec/OCL/2.0/PDF/

離人涙 2024-07-28 21:18:15

对于初学者,我会推荐这本书:Jos Warmer 和 Anneke Kleppe 编写的 The Object Constraint Language: Getting Your Models Ready for MDA(Jos 是 OCL 的主要创建者之一)。

还有这个免费的OCL教程(pdf +幻灯片)

我也很喜欢官方的您已经找到的规范(特别是提供该语言的非正式描述的章节)。

For beginners I would recommend this book:The Object Constraint Language: Getting Your Models Ready for MDA by Jos Warmer and Anneke Kleppe (Jos was one of the main creators of the OCL).

There is also this free OCL tutorial (pdf + slides)

I also like a lot the official specification you already found (specially the chapter offering an informal description of the language).

记忆里有你的影子 2024-07-28 21:18:15

约束的快速解决方案:

context Department inv:
self.staff-> forAll(s1,s2| s1.manager = s2.manager)

context 公司库存:
self.employee->forAll(e| e.manager>>e)

context 公司投资:
self.employee->forAll(e| e.salary<=e.manager.salary)

顺便说一句,我真的没有看到 Company 类的需要(系统中有多少个 Company 类型的对象?) 。 如果约束二和三对于所有公司都成立,那么可以使用 Person 作为上下文来表达它们(例如,使用数字 2): context Person inv: self.manager<>self)

我们还可以添加检查以查看是否员工在进行比较之前有一位经理

A quick solution on the constraints:

context Department inv:
self.staff -> forAll(s1,s2| s1.manager = s2.manager)

context Company inv:
self.employee->forAll(e| e.manager<>e)

context Company inv:
self.employee->forAll(e| e.salary<=e.manager.salary)

Btw, I don't really see the need for the Company class (how many objects of type company do you have in the system?). If constraints two and three are true for all companies then they could be expressed using Person as context in this way (e.g. with number 2): context Person inv: self.manager<>self)

We can also add checks to see if the employee has a manager before doing the comparison

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