: This article mainly introduces how to understand the uml class diagram. if you are interested in the PHP Tutorial, refer to it. In a UML diagram, there are several common relationships: Generalization, implementation, Association, Aggregation, and Composition ), dependency)
1. 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)
[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]: 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. 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. 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]: 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:
The above describes how to understand the uml class diagram, including the content, and hope to be helpful to friends who are interested in the PHP Tutorial.