Composition: a type of association, which is stronger than an aggregation relationship. It requires that the objects represented in common aggregation relationships are responsible for representing the lifecycle of some objects, and the compositing relationships cannot be shared.The whole object is responsible for keeping the object alive. In some cases, it is responsible for destroying some objects. An object that represents the whole can pass objects that represent some parts to another object, and the latter is responsible for the lifecycle of this object. In other words, it means that some objects can only have a composite relationship with one object at each time point, and the latter is responsible for its lifecycle.
For example, the relationship between geese and geese is an aggregation relationship, and the relationship between geese and wings is a combination relationship.
The aggregate link class contains another class as the parameter.
In the goosegroup constructor, goose is used as a parameter to pass in the value. Goose can exist independently of the geese.
Classes in the composite relationship contain the instantiation of another class.
Before instantiating goose, you must first instantiate the wings class (WINGS). The two classes are closely coupled. They have the same life cycle wings class (WINGS) it cannot exist independently from Goose
Different information Encapsulation
In the aggregation relationship, the client can understand both the geese and geese at the same time, because they are independent
In the composite relationship, the client only recognizes the geese and does not even know the existence of the wings, because the wings are tightly encapsulated in the geese.