先决条件 – Java的关联、组合和聚合
协会:
协会被定义为具有共同目的和正式结构的人的组织。它表示描述活动的两个对象之间的二元关系。它是对象之间的关系。例如,一个医生可以与多个患者相关联。
聚合:
聚合是一个集合,或者是事物的集合。这种关系由“has a”关系表示。换句话说,聚合是由许多不同的部分或个体组成的群体、身体或群体。例如,电话号码列表就是聚合的一个例子。
聚合与关联的区别:
Aggregation | Association |
---|---|
Aggregation describes a special type of an association which specifies a whole and part relationship. | Association is a relationship between two classes where one class use another. |
It in flexibile in nature | It is inflexible in nature |
Special kind of association where there is whole-part relation between two objects | It means there is almost always a link between objects |
It is represented by a “has a”+ “whole-part” relationship | It is represented by a “has a” relationship |
Diamond shape structure is used next to the assembly class. | Line segment is used between the components or the class |