类图聚合

发布于 2024-09-02 04:32:29 字数 76 浏览 1 评论 0原文

我遇到了这个定义

聚合有两个属性: 反对称性, 传递性

是什么意思?

谢谢

i came across this definition

Aggregation has two properties:
antisymmetry,
transitivity

What does it mean?

thanks

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

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

发布评论

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

评论(1

半窗疏影 2024-09-09 04:32:29

聚合是一种对象组合,其中对象事物是另一个对象的一部分。这与所有权形成鲜明对比,所有权是一个对象拥有另一个对象。

例如,汽车由许多部件组成 - 发动机、车轮等。这些部件聚合到汽车对象中。

但是,在另一个示例(我在网上找到的)中,如果 Person 对象有一辆汽车,那就不是聚合。人拥有它,但汽车不是人的一部分。

这种差异的一个重要结果是,当一个对象被销毁时,它的聚合部分也应该被销毁。但它拥有的、不属于它的对象,应该保持完整。

所以,对于定义:

反对称 - 我找不到确切的定义,但我的直觉告诉我,这意味着两个对象不能成为彼此的一部分。对象 A 聚合 B,但绝不会同时反之亦然(除非 A 和 B 相等,这更多的是关于集合论而不是 OOP)。我的手臂是我的一部分,但我不能成为我手臂的一部分。

传递性 - 就像数学中的传递性一样。如果A是B的一部分,B是C的一部分,那么A一定是C的一部分。我的手是我的手臂的一部分,我的手臂是我的一部分,因此我的手是我的一部分。

Aggregation is a type of object composition where object thing is part of another object. This is contrasted with ownership, where one object owns the other.

For example, a car is made out of many parts - engine, wheels, etc. The parts are aggregated into the car object.

But, in another example (which I found online) if a Person object has a car, that is not aggregation. The person owns it, but the car is not part of the person.

An important consequence of this difference is that when an object is destroyed, its aggregated parts should be destroyed as well. But objects that it owns, which are not part of it, should remain intact.

So, to the definitions:

Antisymmetry - I couldn't find an exact definition, but my intuition tells me that this means that two objects cannot be part of each other. Object A aggregates B, but never vice versa at the same time (unless A and B are equal, which is more about set theory than OOP). My arm is part of me, but I cannot be part of my arm.

Transitivity - It's just like transitivity in math. if A is part of B, and B is part of C, then A must be part of C. My hand is part of my arm, my arm is part of me, therefore my hand is part of me.

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