Selected from "JAVA Language Programming-Basics (Original Book, 8th Edition)"
Definition: One object can contain another object. The relationship between these two objects is called composition.
Combination is actually a special form of aggregation relationship. Aggregation simulates having (has-a) relationships, representing the attribution relationship between two objects. The owner object in the attribution relationship is called an aggregate object, and its class is called an aggregate class. The subordinate object in the attribution relationship is called the aggregated object, and its class is called the aggregated class.
An object can be owned by several other aggregated objects. If an object belongs to only one aggregate object, then the relationship between it and the aggregate object is called composition. For example: "A student has a name" is a combination relationship, and "A student has an address" is a gathering relationship, because an address can be shared by several students.
In UML, solid rhombus represents a combination relationship, and hollow rhombus represents aggregation relationship. As shown in the picture:
Aggregation relationship is usually represented as a data domain in the aggregation class, as shown in the figure:
Aggregation can also exist between multiple objects of the same class. For example: a person may have one manager or multiple managers. A manager can use variables to represent them, and multiple arrays can be used, as shown in the figure:
At this point, the relationship between aggregation and combination is basically self-evident.
The above article deeply understands the difference and connection between gathering and combining in JAVA is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.