UML: four types of relationships and four types of uml

Source: Internet
Author: User

UML: four types of relationships and four types of uml

Before drawing a class chart, we must first clarify the Four Relationships in UML. There are four common relationships: Generalization, implementation, and Association ), dependency, which includes:Aggregation (Composition), in these relationships they have shear relationships.

I. Concepts

[Generalization]: it is an inheritance relationship that represents a general and special relationship. It specifies how child classes feature all features and behaviors of the parent class.Arrows point to: solid line with a triangular arrow, and arrows point to the parent class.

[Implementation]: Is the relationship between a class and an interface, indicating that the class is the implementation of all features and behaviors of the interface.Arrow points: dotted line with hollow arrow, arrow points to interface.

[Association ]:Is a proprietary relationship that allows a class to know the attributes and methods of another class. The arrow points to the solid arrow.

[Aggregation]: indicates that the entire object has partial objects. Arrow points to: hollow diamond + solid arrow.

[Combination]: a form of aggregation, which has a stronger ownership relationship, emphasizing that the overall and partial life cycles are consistent. Arrow points to: solid diamond + Implementation arrow.

[Dependency]: The semantic relationship between two things. A change in one thing (independent thing) affects another thing (dependent thing ). Arrow pointing: dotted arrow.


Ii. instance Introduction

[Generalization]:A bird belongs to an animal and has its own unique features.

[Implementation]: Dayan achieves the flying interface.

[Association]: Penguins and climate. Penguins live in the South Pole. They need this climate to live. Penguins need to know about climate changes and climate patterns.

[Aggregation]: The computer and External keyboard can exist independently.

[Combination]: The relationship between birds and wings cannot exist independently.
[Dependency]: animals depend on oxygen, water, and food to survive.

Iii. pkcompetition

1. [aggregation] PK [combination]

Similarities: both represent the relationship of 'have'. difference: the length of life cycle.

[Aggregation]: indicates A weak 'havn' relationship. It indicates that object A can contain object B, and their lifecycles may be different, object A does not disappear with object B. The two can exist independently.

[Combination]: indicates A strong 'owner'. They are the relationship between parts and the whole. their lifecycles are the same. Object A disappears with object B, the two cannot exist independently.

Comparison of link strength: Combination> Aggregation

2. [generalization] PK [implementation]

Similarities: equivalent to inheritance. Subclass inherits the parent class, and the parent class extends the Child class.

Comparison of link strength: generalization = implementation

3. [Association] PK [dependency]

Similarities: all indicate dependencies. Difference: the strength of the relationship between classes and the length of time between classes.

[Join] indicates a strong relationship between classes. It indicates a "persistent" Relationship between classes. This relationship generally indicates an important relationship between businesses and needs to be saved, or "persistence" is required, or it needs to be stored in the database.

[Dependency] indicates a weak relationship between classes. It indicates a "temporary, transient" Relationship between classes, which does not need to be saved.

Comparison of link strength: Association> dependency

Comparison of link strength: generalization = implementation> combination> aggregation> association> dependency

Iv. Summary

When I first studied UML, I didn't know much about the four types of relationships. in c # And design patterns, I have mentioned four types of UML relationships and nine types of diagrams. I believe that through repeated learning, they can certainly deepen their understanding.




Expert Q & a uml includes Diagram

This article focuses on the concepts of UML diagrams and relations. UML includes nine types of diagrams: use case diagram, class diagram, object diagram, component diagram, deployment diagram, activity diagram, collaboration diagram, state diagram, and sequence diagram. There are four types of UML relationships. Please refer to this article for details. There are nine types of UML diagrams: use case diagram, class diagram, object diagram, component diagram, deployment diagram, activity diagram, collaboration diagram, state diagram, and sequence diagram. Using Case, class, and sequence diagrams in these diagrams is the most useful. Based on the purpose, you can divide a UML diagram into two types: Structural Diagram and behavior diagram. Structural Diagram: Describes the static structure of the system. It is most useful when displaying the relationships between classes in the system. It is obvious that to describe the static structure of a design pattern, it is appropriate to use the class diagram and object diagram in the UML diagram. It is obvious that to describe the behavior characteristics of a design pattern, it is appropriate to use the state diagram and time sequence diagram in the UML diagram. It should be pointed out that a system design using UML often starts from the use case diagram and should be case-driven.

Summary of several types of UML class diagrams

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 are specific to 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. arrow pointing to 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]: a dotted line with a triangular arrow. the arrow points to interface 3. association: an Association that allows a class to know the attributes and methods of another class, the relationship between husband and wife can be bidirectional or unidirectional. Two-way association can have two arrows or no arrows, and one-way Association has one arrow. [Code embodiment]: member variable [Arrow and pointing]: a solid line with a common arrow pointing to the owner. The teacher and the student are two-way connections. The teacher has multiple students, the student 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. Join for itself: 4. Aggregate [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 variable [Arrow and direction]: solid line with hollow diamond, the diamond points to the whole 5. composition: 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 variable [Arrow and direction]: solid line with solid diamond, the diamond points to the whole 6. dependency: A Dependency is a type of use relationship, that is, the implementation of a class requires the assistance of another class. Therefore, do not use two-way Dependency whenever possible. [Code expression]: local variables, method parameters, or call static methods [Arrow and direction]: dotted line with arrows, pointing to the strong and weak order of various relationships of the User: generalization = implementation> combination> aggregation> association> dependency The following UML diagram shows the relationships of various types of diagrams in a visual manner:

Related Article

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.