Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How many relationships are there in the UML class diagram

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how many relationships there are UML class diagrams, I believe that most people still do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

UML:

Triangular arrow solid line, inheriting

Triangular arrow dotted line, realizing

The normal arrow solid line, the association relationship, points to the owner. Code representation: member variables

Ordinary arrow dotted line: dependency, pointing to the user. Code representation: local variables, method parameters, or calls to static methods

Hollow diamond solid line, aggregation relationship, pointing to the whole. Code representation: member variables (aggregation: parts can exist separately from the whole)

Solid diamond solid line, combinatorial relationship, pointing to the whole. Code embodiment: member variables (combination: parts cannot exist separately from the whole)

In UML class diagrams, there are the following common relationships: Generalization, Realization, Association, Aggregation, Composition, Dependency.

1. Generalization (Generalization)

[generalization relationship]: an inheritance relationship that represents a general and special relationship that specifies how the subclass specializes all the characteristics and behavior of the parent class. For example, a tiger is a kind of animal, which has both the characteristics of a tiger and the commonness of animals.

[arrow pointing]: a solid line with a triangular arrow pointing to the parent class

two。 Implement (Realization)

Implementation relationship: a relationship between a class and an interface, indicating that a class is the implementation of all features and behaviors of an interface.

[arrow pointing]: a dotted line with a triangular arrow pointing to the interface

3. Association (Association)

[relationship]: a relationship of ownership that makes one class know the properties and methods of another; for example, teachers and students, husbands and wives can be two-way or one-way. A two-way association can have two arrows or no arrow, and an one-way association can have an arrow.

[code embodiment]: member variables

[arrow and pointing]: a solid line with an ordinary arrow pointing to the owner

In the picture above, there is a two-way relationship between the teacher and the student. the teacher has multiple students, and the students may have multiple teachers. But the relationship between students and a course is an one-way relationship, a student may have to take more than one course, the course is an abstract thing he does not have students.

The following figure shows the self-association:

4. Aggregation (Aggregation)

[aggregate relationship]: it is the relationship between the whole and the part, and the part can exist alone without the whole. If the relationship between the car and the tire is a whole and part, the tire can still exist without driving.

Aggregation relation is a kind of association relationship, which is a strong association relationship; relevance and aggregation cannot be distinguished in grammar, so we must examine the specific logical relations.

[code embodiment]: member variables

[arrow and pointing]: a solid line with a hollow diamond pointing to the whole

5. Combination (Composition)

[combinatorial relationship]: it is the relationship between the whole and the part, but the part cannot exist alone without the whole. If the relationship between the company and the department is a whole and part, there would be no department without the company.

Combinatorial relationship is a kind of association relationship, which is stronger than aggregation relationship. It requires that the object representing the whole in the ordinary aggregation relationship is responsible for the life cycle of the object that represents the part.

[code embodiment]: member variables

[arrow and pointing]: a solid line with a solid diamond pointing to the whole

6. Dependency (Dependency)

Dependency: 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 representation]: local variables, parameters of methods, 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 vividly shows the relationships of various class diagrams:

These are all the contents of this article entitled "how many relationships are there in UML Class diagrams?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report