Association (weakest relationship):
The relationship is also not temporary, generally long-term, and the relationship between the two sides is generally equal. Associations can be one-way, two-way. At the code level, the associated class B appears in the association Class A as an attribute of the class, or the association Class A refers to a global variable of the type being associated with Class B.
such as students and teachers
Teacher to lecture, this is a method, to pass a parameter in, parameter is student object
Inheritance relationships (avoid multiple inheritance)
Inheritance refers to the ability of a class (called a subclass, sub-interface) to inherit the functionality of another class (called a parent class, parent interface) and to increase its own new functionality. Inheritance relationships in Java are clearly identified by keyword extends and are generally not controversial at design time.
Can be said, what is a kind of what.
For example, the main class parent class is the athlete, then the athlete has the ball player, the ball player and the table tennis player. (a table tennis player is a ball player, a ball player is an athlete)
Aggregation relationships (aggregation, composition)
Aggregation is a special case of association, which embodies the relationship between the whole and the part. At this point, the whole and the parts are separable, they can have their own life cycle, some can belong to more than one whole object, or can be shared for multiple whole objects.
Can be considered as what is part of what
The team, for example, has a captain who is both the captain of the football team and the captain of the basketball team. A player is a basketball player and a ping-pong player.
Aggregation: This part of the class can be of this class, or it can be another class,
Combination: Each part belongs to only one class
Implementing relationships
Implementation refers to a class class that implements the interface (which can be multiple), and implementation is the most common relationship between classes and interfaces. In Java, such relationships are explicitly identified by the keyword implements.
Interface: Just define the method, how to implement the subclass to do
such as driving (interface) This method, Class A can be implemented, Class B can also be implemented.
Java classes associated with classes, aggregations, inheritance, implementation relationships