In addition, the relationship between UML class diagrams

Source: Internet
Author: User

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:


In addition, the relationship between UML class diagrams

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.