UML 聚合与关联 [英] UML aggregation vs association

查看:27
本文介绍了UML 聚合与关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来了,还有一个关于聚合和关联的问题.我想学习 UML 的一些基础知识,所以我开始阅读 Martin Fowler 的UML distilled".我阅读了关于类的两章,我认为有一件事我无法完全理解,那就是聚合与关联.书中有这样一句话:

Here I am, with another question about aggregation and association. I wanted to learn some basics of UML, so I started reading "UML distilled" by Martin Fowler. I read both chapters about classes, and there is one thing that I can't fully grasp I think, and that is aggregation vs association. In the book there is this quote:

在 UML 出现之前,人们通常对什么是聚合以及什么是聚合相当模糊协会.无论含糊与否,他们总是与其他人不一致.其结果,许多建模者认为聚合很重要,尽管原因各不相同.所以UML包括聚合(图 5.3)但几乎没有任何语义.正如 Jim Rumbaugh 所说,想想看作为建模安慰剂"[Rumbaugh,UML 参考].

In the pre-UML days, people were usually rather vague on what was aggregation and what was association. Whether vague or not, they were always inconsistent with everyone else. As a result, many modelers think that aggregation is important, although for different reasons. So the UML included aggregation (Figure 5.3) but with hardly any semantics. As Jim Rumbaugh says, "Think of it as a modeling placebo" [Rumbaugh, UML Reference].

从我在 Stack Overflow 上阅读的这句话和主题中了解到,我使用这两种关系中的哪一种并不重要,它们的意思基本相同,或者是否存在使用聚合而不是关联的任何情况将是合理的和/或我不能在不改变类图的含义"的情况下将一个更改为另一个?

As I understand from this quote and topics that I read on Stack Overflow it doesn't matter which one of those two relations I use, they mean basically the same, or is there any situation where the usage of aggregation instead of association would be justified and/or I could not change one to the other without changing the "meaning" of a class diagram?

我问这个,因为这本书是 2003 年的,在那几年里有些事情可能会发生变化.

I am asking this, because this book is from 2003 and some things could have changed during those few years.

推荐答案

Rumbaugh 的声明最有说服力,也是 Bob 叔叔的好建议.正如我所说的其他地方,聚合在语义上如此薄弱,以至于没有提供任何实际有益的东西.它只有一个有效的极端情况(递归关系的非循环性),但是很少有人知道和理解这一点.所以你最终不得不在评论中指出.

Rumbaugh's statement is the most telling and Uncle Bob's good advice. As I've said elsewhere, Aggregation is semantically so weak as to offer nothing practically beneficial. It only has one valid corner case (acyclicity of recursive relationships) however few people know and understand that. So you end up having to point out in comments anyway.

我只是不使用它.并且从来没有感觉到任何损失.坚持简单的二元关联,并专注于真正重要的事情 - 获得基数和正确命名.与尝试决定不可判定的关联与聚合相比,您将从中获得更多.

I just don't use it. And have never felt any loss. Stick with simple binary associations and focus on what really matters - getting the cardinality and naming right. You'll get far more from that than trying to decide the undecidable association vs. aggregation.

这篇关于UML 聚合与关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆