在 ECore 中,遏制和参考之间有什么区别?

发布于 2024-09-25 01:36:12 字数 97 浏览 8 评论 0原文

在 ECore 实体之间创建引用时,可以将引用标记为“包含”。 有人可以用简单的语言向我解释一下普通引用和包含之间有什么区别吗?到目前为止我发现的定义和解释对我来说并没有什么用处。

When creating references between ECore entities there is the possibility to mark a reference as "containment".
Can somebody explain me in easy words what's the difference between a plain reference and a containment? The definitions and explainations I found so far didn't do the trick for me.

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

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

发布评论

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

评论(2

﹏雨一样淡蓝的深情 2024-10-02 01:36:12

参考:参考是一种简单的“A 知道 B”关系。单独的引用不会相互影响。 A可以认识B,B也可以认识C。因此,如果你有A,你可以通过B去C。如果你删除引用,A、B和C仍然存在,只是他们不再认识彼此。

包含:包含是“A有B”类型的关系。通常用于列表,例如“A 有多个 B”。然后,ECore/EMF 可以对此类集合执行原子命令,例如将所有对象从一个容器移动到另一个容器。它还可以强制实施约束,例如所包含对象的最小数量或所包含对象的最大数量,或者确保所包含的对象不包含在任何其他容器中。

示例

假设您有一个名为 ShoppingCart 的对象,其中包含一个名为 Customer 的引用和一个名为 OrderedProducts 的容器。 OrderedProducts 具有对Product 的引用。

这个模型告诉你什么?

  • 您可以将客户分配到购物车。如果您从 ShoppingCart 中删除 Customer,Customer 对象本身仍将存在(例如在数据库中)。
  • OrderedProduct 对象需要 ShoppingCart 才能存在。如果您从购物车中删除一项,它将不复存在。
  • 每个 OrderedProduct 都有对数据库中现有产品的引用。如果您从购物车中删除其中一个已订购产品,数据库中的产品仍将存在 - 只是该特定客户的该产品订单消失了

Reference: A reference is a plain "A knows B" relation. Separate references do not influence each other. A can know B and B can know C. Hence, if you have A, you can go to C over B. If you remove the reference, A, B and C will still exist, they just don't know each other any more.

Containment: A containment is the "A has B" kind of relation. Usually used for lists, e.g. "A has multiple B". ECore/EMF can then perform atomic commands on such collections, such as move all objects from one containment to another. It can also enforce constraints, such as a minimum amount of contained objects or a maximum amount of contained objects, or ensuring that the contained object is not contained in any other containment.

Example:

Assume you have an object called ShoppingCart with a reference called Customer and a containment called OrderedProducts. The OrderedProducts has a reference to a Product.

What does this model tell you?

  • You can assign a Customer to the ShoppingCart. If you remove the Customer from the ShoppingCart, the Customer object itself will still exist (e.g. in the database)
  • The OrderedProduct objects need a ShoppingCart to exist. If you remove one from the ShoppingCart, it will cease to exist.
  • Each OrderedProduct has a reference to an existing Product in the database. If you remove one of the OrderedProducts from the ShoppingCart, the Product in the database will still be there - just the order of that product for that specific customer is gone
↙厌世 2024-10-02 01:36:12

参考:可以像UML中的关联

包含:是UML中的组合关系

如果您设置包含 为 true,则该行将有一个填充的侧面,显示包含/组成。这是我观察到的。

Reference : can be like association in UML

Containment : is the composition relation from UML

Also this can be seen in the EMF diagram, if you set the containment to true, then the line will have a filled side, showing the containment/composition. This is what I have observed.

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