标签:call ... -o img data general mon ast csdn
本文參考例如以下资料(建议阅读):
a). difference-aggregation-acquaintance-and-composition-as-used-by-gang-of-four
b). AssociationVsAggregationVsComposition
c). Design Patterns Elements of Reusable Object-Oriented Software
d). Java疯狂讲义(第三版)
我看到的是这本书的第三版,在2.2.2中有关UML的类图的概念理解上,书中所用的图例如以下:
这副图上面的文字(书里面的排版)我认为没有太大的问题(实际上我认为另一些表达欠妥的地方)。摘录例如以下:
关联关系包括两种特例:聚合和组合,它们都有部分和总体的关系,但通常觉得组合比聚合更加严格。
当某个实体聚合成还有一个实体时。该实体还能够同一时候是还有一个实体的部分,比如。学生即能够是篮球俱乐部的成员。也能够是书法俱乐部的成员;当某个实体组合成还有一个实体时。该实体则不能同一时候是一个实体的部分。
聚合使用带空心菱形框的实线表示,组合则使用带实心菱形框的实线表示。
图片下片的文字就狗屁不通了,摘录例如以下:
Student和BasketBallClub存在聚合关系。即1个或多个Student实体能够聚合成一个BasketBallClub实体。而Arm(手臂)和Student之间存在组合关系,2个Arm实体组合成一个Student实体。
我们介绍一些背景知识热热身:
在Design Patterns by Gang of Four(參考资料c的别名) 1.6节中有一段叫做Relating Run-Time and Compile-Time Structures的段落:
Consider the distinction between object aggregation and acquaintance and how
differently they manifest themselves at compile- and run-times. Aggregation
implies that one object owns or is responsible for another object. Generally we
speak of an object having or being part of another object. Aggregation implies
that an aggregate object and its owner have identical lifetimes.
Acquaintance implies that an object merely knows of another object. Sometimes
acquaintance is called "association" or the "using" relationship. Acquainted
objects may request operations of each other, but they aren‘t responsible for
each other. Acquaintance is a weaker relationship than aggregation and suggests
much looser coupling between objects.
...
Ultimately, acquaintance and aggregation are determined more by intent than by
explicit language mechanisms. The distinction may be hard to see in the
compile-time structure, but it‘s significant. Aggregation relationships tend to
be fewer and more permanent than acquaintance. Acquaintances, in contrast, are
made and remade more frequently, sometimes existing only for the duration of an
operation. Acquaintances are more dynamic as well, making them more difficult
to discern in the source code.
大意是在讨论两个词语:aggregation和acquaintance。
而有意思的是随后的UML中却相同定义了一个aggregation的概念,然后就是association、composition。
为什么说这有意思呢?由于两者对相同的词语表达的概念实际上有所出入,UML中的aggregation实际上说的是GoF(參考资料c的别名)中的acquaintance,UML中的composition则是GoF中的aggregation。只是现今普遍採用的是UML中的概念了。
通过除了d的參考资料我们能够得知。association说的实际上是一种对象之间的所属与生命周期的关系。而不是本文图片以下表达出的("即1个或多个Student实体能够聚合成一个BasketBallClub实体;而Aram(手臂)和Student之间存在组合关系。2个Arm实体组合成一个Student实体")被聚合/组合对象构建出主体对象的方式。这中间的差别非常微妙。语文没过200分的非常难发现(呀。谁扔的砖头)。
Student和BasketBallClub是聚合关系(准确来说BasketBallClub聚合Student),能够得出的结论是BasketBallClub能够有0个或者多个Student,且BasketBallClub对Student的生命周期不负不论什么责任,相同BasketBallClub死亡也跟Student不会有一毛钱关系。
2个Arm和Student是组合关系(准确来说是Student组合Arm),能够得出的结论是Student必然会有2个Arm,且Student对这2个Arm的生命周期负有责任,假设Student死亡Arm也会死亡。
综上。本文图片下的文字的说法简直就是毫无依据。一个人想吃饭,我们能断定饭想被他吃么?
标签:call ... -o img data general mon ast csdn
原文地址:http://www.cnblogs.com/jzdwajue/p/7100468.html