There are several common relationships between classes

  1. USES-A: Dependency. Type A will use Type B. This relationship is accidental and temporary. However, the changes in category B will affect category A. This is reflected in the code as: The parameters in the A method include the B class.

  2. Association relationship: Type A will use type B. This is a strong dependency, which is long-term and not accidental. The performance in the code is: A class member variable contains B class.

  3. HAS-A: aggregation relationship, ownership relationship, is a special case of association relationship, it is the relationship between whole and part. For example, the relationship between a flock of birds and birds is an aggregation relationship, and every part of the flock is a bird.

  4. IS-A: Represents inheritance. The parent category and sub category, this will not be explained.

  5. contains-a: Combination relationship is also a special case of association relationship. It reflects a contains-a relationship, which is stronger than aggregation and is also called strong aggregation. It also reflects the relationship between the whole and the part, but the whole and the part are inseparable.

Guess you like

Origin blog.csdn.net/qq_37669050/article/details/100525559