In a UML diagram, there are several common relationships: generalization, implementation, association, aggregation, and composition ), dependency)
1.Generalization (Generalization)
[Generalized relationship]: an inherited relationship that represents a general and special relationship. It specifies how child classes feature all features and behaviors of the parent class. For example, a tiger is a type of animal, that is, the characteristics of a tiger and that of animals.
[Arrow pointing]: solid line with a triangular arrow. the arrow points to the parent class.
2.Implementation (Realization)
[Implementation relationship]: The relationship between a class and an interface, indicating that a class is the implementation of all features and behaviors of an interface.
[Arrow pointing]: dotted line with a triangular arrow. the arrow points to the interface.
3.Association (Association)
[Association]: A relationship that enables a class to know the attributes and methods of another class. For example, the relationship between a teacher and a student, and between a husband and a wife can be bidirectional, it can also be unidirectional. Two-way association can have two arrows or no arrows, and one-way Association has one arrow.
[Code embodiment]: member variables
[Arrow and direction]: solid line with a normal arrow, pointing to the owner
There is a two-way relationship between teachers and students. Teachers have multiple students, and students may also have multiple teachers. However, the relationship between a student and a course is one-way association. A student may have to take multiple courses. The course is an abstract thing and he does not have any students.
Associate yourself:
4.Aggregate (Aggregation)
[Aggregation relationship]: The relationship between the whole and the part, and the part can exist independently from the whole. If a car and a tire are in the overall and partial relationship, the tire can still exist when it leaves the car.
An aggregation relationship is a strong association relationship. The association and aggregation cannot be distinguished in syntax, and the specific logical relationship must be investigated.
[Code embodiment]: member variables
[Arrow and direction]: solid line with hollow diamond. The diamond points to the whole.
5. Combination(Composition)
[Composite relationship]: it is the relationship between the whole and the part, but the part cannot exist independently from the whole. If the relationship between a company and a department is a whole and a part, no department exists without the company.
A composite relationship is a type of association relationship, which is stronger than an aggregation relationship. It requires that the object representing the whole in a general aggregation relationship represents the lifecycle of some objects.
[Code embodiment]: member variables
[Arrow and direction]: solid line with solid diamond. The diamond points to the whole.
6.Dependency(Dependency)
[Dependency]: it is a type of use relationship, that is, the implementation of a class requires the assistance of another class, so try not to use two-way mutual dependency.
[Code representation]: local variables, method parameters, or calls to static methods
[Arrow and direction]: a dotted line with an arrow pointing to the user
Strong and weak order of various links:
Generalization=Implementation>Combination>Aggregation>Association>Dependency
The following UML diagram visually shows the relationship between different types of diagrams:
[Reprint] http://www.open-open.com/lib/view/open1328059700311.html
UML class diagram relation mode and C ++ Code Description: http://blog.sina.com.cn/s/blog_5ea0192f0100dyvr.html