惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Last Watchdog
The Last Watchdog
AI
AI
Webroot Blog
Webroot Blog
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog RSS Feed
小众软件
小众软件
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Vercel News
Vercel News
Y
Y Combinator Blog
P
Proofpoint News Feed
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
F
Fortinet All Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
V2EX
MongoDB | Blog
MongoDB | Blog
SecWiki News
SecWiki News
The Register - Security
The Register - Security
博客园_首页
T
Threat Research - Cisco Blogs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recorded Future
Recorded Future
V
Vulnerabilities – Threatpost
I
InfoQ
雷峰网
雷峰网
C
Check Point Blog

博客园 - 雨帘

农村出身的80后身处都市的十大尴尬 HP大中华区总裁孙振耀退休感言(转) 转——如何让上司支持自己的想法 WMS部分互操作完成 支持WMS GeoMapNet开发日志——导出 地图缓存的研究 Research on Tile Map 西湖的残冬 新型统计图 SVG的WebGIS实例 大地经纬度和国家标准坐标转换 建立在不同的数据库引擎的Sql问题,无思路 三层设计模式初步分离 IMS服务自动注册功能实现 Personal ArcSDE不支持IIS6的使用 VML脚本产生 脚本操作table 为什么我的ActiveSync连接不上模拟器
聚合(Aggregation)和组合(Composition)的区别
雨帘 · 2007-11-04 · via 博客园 - 雨帘

聚合(Aggregation)

一種鬆散的對象閒的關係

部分可獨立于聚合而存在

 关联是表示两个类的一般性联系,比如“学生”和“老师”就是一种关联关系;聚合表示has-a的关系,是一种相对松散的关系,聚合类不需要对被聚合类负责,如下图所示,用空的菱形表示聚合关系:
从实现的角度讲,聚合可以表示为:
class A {...} class B { A* a; .....}  

当B类销毁的时候,A的指针a并不会被销毁的,在内存中还有a的位置了。
 

組合(Composition)

一種非常強烈的對象之間的關係

組合一旦銷毀的話,必須銷毀所有部分或把負責他們的權利轉移給其他對象

而组合表示contains-a的关系,关联性强于聚合:组合类与被组合类有相同的生命周期,组合类要对被组合类负责,采用实心的菱形表示组合关系:
实现的形式是:
class A{...} class B{ A a; ...}
B类销毁了后,A也被同时销毁,在内存中就没有a的位置了。