Unified Modeling Language (UML), also known as Unified Modeling Language or Standard Modeling Language, is an OMG standard started in 1997. It is a graphical language that supports modeling and software system development, providing models for all stages of software development. and visualization support, from requirements analysis to specification, to construction and configuration. The development of object-oriented analysis and design (OOA&D, OOAD) methods reached a climax from the late 1980s to the mid-1990s, and UML was the product of this climax. It not only unified the representation methods of Booch, Rumbaugh and Jacobson, but also further developed them and finally unified them into a standard modeling language accepted by the public.
In UML class diagrams, several commonly used relationships are: Generalization, Realization, Association, Aggregation, Composition, Dependency. Next, through this This article will give you a detailed explanation one by one. The specific details are as follows:
1. Generalization
[Generalization relationship]: It is an inheritance relationship that expresses the general and special relationship. It specifies how the subclass specializes all the characteristics and behaviors of the parent class. For example: Tiger is a kind of animal, which has the characteristics of tiger as well as commonalities among animals.
[Arrow pointing]: solid line with triangular arrow, the arrow points to the parent class
2. Realization
[Implementation relationship]: It is a relationship between a class and an interface, indicating that the class is the implementation of all the characteristics and behaviors of the interface.
[Arrow pointing]: A dotted line with a triangular arrow, the arrow points to the interface
3. Association
[Association relationship]: It is a kind of ownership relationship, which allows one class to know the attributes and methods of another class; such as: teacher and student, husband and wife
Associations can be bidirectional or unidirectional. Bidirectional associations can have two arrows or no arrows, and unidirectional associations have one arrow.
[Code Reflection]: Member variables
[Arrow and pointing]: A solid line with an ordinary arrow pointing to the owner
In the picture above, teachers and students are bidirectionally related. Teachers may have multiple students, and students may also have multiple teachers. However, the relationship between a student and a course is a one-way relationship. A student may take multiple courses. A course is an abstract thing and it does not own students.
The picture above shows its own relationship:
4. Aggregation
[Aggregation relationship]: It is a relationship between a whole and a part, and a part can exist independently of the whole. For example, a car and a tire have a relationship between a whole and a part, and the tire can still exist without the car.
The aggregation relationship is a type of association relationship and is a strong association relationship; association and aggregation cannot be distinguished grammatically, and the specific logical relationship must be examined.
[Code Reflection]: Member variables
[Arrow and pointing]: A solid line with a hollow rhombus, the rhombus points to the whole
5. Composition
[Combined relationship]: It is the relationship between the whole and the parts, but the parts cannot exist independently of the whole. For example, the relationship between the company and the department is the relationship between the whole and the part. Without the company, there would be no department.
The combination relationship is a type of association relationship and is a stronger relationship than the aggregation relationship. It requires that the object representing the whole in the ordinary aggregation relationship is responsible for the life cycle of the object representing the part.
[Code Reflection]: Member variables
[Arrow and pointing]: A solid line with a solid rhombus, the rhombus points to the whole
6. Dependency
[Dependency]: It is a usage relationship, that is, the implementation of one class requires the assistance of another class, so try not to use two-way interdependence.
[Code performance]: local variables, method parameters or calls to static methods
[Arrow and pointing]: A dotted line with an arrow pointing to the user
The order of strength of various relationships:
Generalization = Implementation > Composition > Aggregation > Association > Dependency
The following UML diagram shows various class diagram relationships more vividly:
The above is the entire narrative of this article, I hope you like it.