Reading directory
I. Principles of synthesis/aggregation multiplexing
Ii. What is synthesis?
3. What is aggregation?
4. Why not use synthesis/aggregation instead of class inheritance?
V. Principle structure of merging/aggregation multiplexing
I. Principles of synthesis/aggregation multiplexing
Use merging/aggregation whenever possible, and do not use class inheritance whenever possible
Ii. What is synthesis?
.Synthesis represents a strong relationship of ownership, reflecting the strict relationship between the part and the whole, and the same as the overall life cycle. For example, a person has two arms, the arm and the person are the relationship between the part and the whole. If a person dies, the arm will be useless. That is to say, the arm and the person's life cycle are the same.
.The compositing relationship is expressed by solid diamond + solid line.
3. What is aggregation?
.Aggregation indicates A weak relationship of ownership. Object A can contain object B, but object B is not part of object A. For example, A person is A group animal, therefore, each person belongs to a group. A group can have multiple people, so the group and people are aggregated.
.The aggregation relationship is represented by a hollow diamond + solid line.
4. Why not use synthesis/aggregation instead of class inheritance?
.The Object Inheritance relationships are defined at compilation, so the implementation of child classes inherited from the parent class cannot be changed at runtime.
.The implementation of a subclass is closely related to its parent class, so that any changes in the implementation of the parent class will inevitably lead to changes in the subclass.
.When you reuse child classes, if the inherited implementation is not suitable for solving new problems, the parent class must be overwritten or replaced by other more suitable classes.
This dependency limits flexibility and ultimately limits reusability.
V. Principle structure of merging/aggregation multiplexing
1, 2, and n are referred to as the base number, indicating that the class at this end can have several instances. Obviously, a person has two arms. If a class may have multiple instances, n indicates that there may be countless people in a group.