The Six Types of Class relationships
There are six main types of relationships between classes: inheritance , realization / implementation , composition , aggregation , association, and dependency . The arrows for the six relationships are as follows:
Then we come to understand the specific content of the class relationship.
Six types of relationships
In the six types of relationships, the code structure of the three types of relationships such as composition , aggregation , and association is the same as using attributes to store the references of another class. Therefore, they must be distinguished by the relationship between the contents.
Realization / Implementation
For example: cars and ships are vehicles, and the vehicle is just an abstract concept of a mobile tool, and the ship and the vehicle realize the specific mobile functions.
The combination relationship represents the relationship between the whole and part of the class, and the overall and part have a consistent lifetime. Once the overall object does not exist, some of the objects will not exist, and they will all die in the same life.For example, a person is composed of a head and a body. The two are inseparable and coexist.
For example, bus drivers and work clothes and hats are part of the overall relationship, but they can be separated. Work clothes and hats can be worn on other drivers. Bus drivers can also wear other work clothes and hats.
1..1: Only one
0..*: Zero or more
1..*:one or more
0..1: No or only one
m..n: at least m, at most n (m<=n)
A dependency relationship is a “use” relationship. A change in a particular thing may affect other things that use it, and use a dependency when it is necessary to indicate that one thing uses another.For example: The car relies on gasoline. If there is no gasoline, the car will not be able to drive.