差异聚集,熟人和组成(由四方使用) [英] Difference aggregation, acquaintance and composition (as used by Gang Of Four)

查看:96
本文介绍了差异聚集,熟人和组成(由四方使用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读设计模式:可重用面向对象软件的元素,并解释了聚合熟人。这是一个摘录(对不起,如果太久了,但我认为所有这一切对解释这个问题很重要):

I have been reading Design Patterns: Elements of Reusable Object-Oriented Software and got to the part explaining aggregation and acquaintance. Here is an excerpt (sorry if it is too long but I deemed all of it to be important to explain this question):


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.


我的混乱部分是这里描述的聚合具有组合 - >组合对象包含/管理其他对象及其生命周期的特征。

The confusing part for me is that aggregation described here has traits of composition -> composing object contains/manages other objects and their life-cycles are bound.

另一方面,该摘录中定义的熟人具有聚合的特征 - >聚合对象只知道对象,但不管它们。

On the other hand acquaintance defined in that excerpt has traits of aggregation -> aggregating object only knows about the objects but it does not manage them.

还有部分


Sometimes acquaintance is called "association" or the "using" relationship. 


令人困惑,因为我认为聚合组合关联聚合是较少的耦合。

is confusing as I thought that both aggregation and composition are forms of association with aggregation being the less coupling one.

可以这样做,作者是指聚合 as 熟人组合作为聚合或者我错过了一些

Can it be that the authors are referring to aggregation as acquaintance and to composition as aggregation or am I missing something?

推荐答案

我已经教过的是你写的:

What I have been taught is as you write:


可以说,作者将聚合指向为
认识组合聚合,或者我缺少
某事?

Can it be that the authors are referring to aggregation as acquaintance and to composition as aggregation or am I missing something?

是的。我的理解是:


  1. 分析视图中,考虑关联

  2. 设计视图中,详细说明每个关联 - 将它们分为两组:

    • 聚合(对象可以独立生活的更自由的关系)和

    • 组合(一个对象的关系越紧密负责其他人的生命周期)。

  1. In the analysis view, think in terms of association.
  2. In the design view, specify each association in deeper detail - divide them into two groups:
    • aggregation (the more free relationship where the objects may live independently) and
    • composition (the more tight relationship where one object is responsible for the life cycle of the other).

这篇关于差异聚集,熟人和组成(由四方使用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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