关联与聚合 [英] Association vs. Aggregation

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

问题描述

我已经回顾了很多关于这些事情的信息,但是无法理解它们之间有什么区别?在Fowler的UML Distilled中说,Aggreagation绝对没有意义,因此作者建议不要在图表中使用它。
请解释,当我应该使用它们以及它将如何影响java代码时。

I have reviewed a lot of information about these things, but can't understand what is the difference between them? In Fowler's UML Distilled says that Aggreagation is strictly meaningless, so author recommends not to use it in diagrams. Explain, please, when I should use each of them and how it will influence on java code.

推荐答案

这个是一个非常有争议的问题。正如Martin 在答案中解释,该订单汇总了产品。这可以认为是真的。 Grady Booch在他的面向对象的分析和设计中提供了一个类似的关联示例 - 销售与该销售中的产品相关联,反之亦然。销售不会聚合产品。因此,所有示例都应该是特定于域的,因为从另一个角度来看,关联可能变得更具体。另一个例子是使用段落的文档组成。

This is a very arguable question. As Martin explains in the answer, the Order aggregates the Product. And this can be considered true. Grady Booch in his "Object-Oriented Analysis and Design" brings a similar example for association - a sale is associated with products in that sale, and vice versa. And a sale doesn't aggregate products. So all examples should be domain-specific, because from another point of view the association may become more specific. Another example is the composition of Documents using Paragraphs.

因此,该字段中的所有内容都强烈依赖于上下文。这是OOP。

So everything in this field strongly depends on the context. This is the OOP.

您可以尝试将您的知识应用于您要设计的特定项目。我建议你阅读Grady Booch的书,如果你还没有这样做的话。自那以来已经写了很多书,但它仍然是OO *的圣经。

You can try to apply your knowledge to a particular project you are going to design. I would recommend you to read Grady Booch's book, if you haven't done it yet. Lots of books have been written since it, but it is still the Bible of OO*.

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

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