Java中的关联与聚合与组合 [英] Association vs. Aggregation vs. Composition in Java
问题描述
我试图了解这些术语的含义。我带来了几个例子:
I'm trying to understand what these terms mean. And I came with few examples like:
聚合:Facebook 有用户
Aggregation : Facebook has a user
组成:Facebook 中的每个用户都有一个会话。
Composition : Each user in facebook has a session.
关联:人们使用浏览器
但我对有和使用我的例子感到困惑。为什么不能用户使用 Facebook帐户或Facebook 使用会话对用户进行身份验证?
But I'm getting confused with has a and uses a examples of mine. Why can't it be User uses a facebook account or Facebook uses a session to authenticate user?
就OOP而言是错误的吗?我错过了哪个概念?
Is that wrong in terms of OOP? Where I'm missing the concept?
推荐答案
使用关系意味着两件事
- >两者都可以独立存在
->both can exist independently
- >来自整个分类器的数据流(人 )到零件分类器(浏览器)
->Data flows from the whole classifier(people) to the part classifier(browser)
具有关系意味着两件事
- >零件分类器的生命周期(会话)取决于整个分类器的生命周期( facebook )
->the lifetime of the part classifier(session) is dependent on the lifetime of the whole classifier(facebook)
- >数据通常只在一个方向上流动(即从整个分类器( facebook )流向零件分类器(会话))。
->data usually flows in only one direction (that is, from the whole classifier(facebook) to the part classifier(session)).
这篇关于Java中的关联与聚合与组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!