[Cainiao crazy UML series] -- analysis of four types of UML relationships

Source: Internet
Author: User
In UML, a link is very important. it abstracts the links between objects and forms a link structure. The following describes the four types of relationships in UML: association, dependency, generalization, and implementation. & #160; & #160; 1. Examples & #160; & #160; 1. Association & #160; & #160; associations are used to connect objects with structural relationships. they can be connected to the same class or

In UML, a link is very important. it abstracts the links between objects and forms a link structure. The following describes the four types of relationships in UML: association, dependency, generalization, and implementation.


I. Examples
1. Association)

An association is used to connect objects with structural relationships. it can be connected to the same or different classes, or bidirectional or unidirectional.

Example: Unidirectional Association:People turn on the TV, which is a one-way Association.


Bidirectional association:The relationship between people and the company. a person is an employee of the company and a person's employer. (One company has 0 or n employees)

(1) Aggregate)


It represents the relationship between object objects and the relationship between the whole and the part. the whole is composed of parts, but the relationship is not strongly dependent. that is to say, the part will not disappear according to the disappearance of the whole. The aggregation relationship is displayed in a straight line with a hollow diamond arrow pointing to the whole.

Books and styles are a set of aggregation relationships. styles have sizes and colors. they can be part of a book. However, once the book is separated from the entity, the entity style can also exist independently.


(2) Composition)

It indicates the relationship between objects and parts of objects, and represents the relationship between the whole and the part. the whole has a part, which is a strongly dependent aggregation relationship, and the part disappears with the disappearance of the whole. The combination relationship is expressed in a straight line with a solid diamond arrow. the arrow points to the parent object of the combination, that is, the whole, indicating that the part belongs to the whole.


A combination of books and pages. when an entity page is detached from a book, it does not exist and disappears along with the book.



2. Dependency)
It indicates that an object uses the relationship of another object at runtime, which is generated at runtime. the dependencies vary with different runtime scenarios. Dependencies are represented by a dotted line with arrows. arrows point to the dependent objects. You can also use the relationship between tables.
A person uses a knife to cut an apple. In this scenario, the person is dependent on a knife.


3. Generalization)
Represents the inheritance relationship between objects, indicating that one class inherits from another class. Uses a straight line of the hollow arrow to indicate that the arrow points to the inherited object. Employees and employers are inherited from humans.



4. implement (Realize)
The implementation of the class interface is represented by a dotted line with a hollow arrow, and the arrow points to the interface. II. Comparative Analysis
1. aggregation VS combination

Both represent the relationship between the whole and the part, but the difference is that the combination is strongly dependent on the aggregation relationship, and the part does not exist after the whole. However, the aggregation relationship can still exist even if it is separated from the whole.


2. associate VS dependencies

At the beginning, we started to identify whether to perform customs clearance and dependency. later, we saw in the video that the dependency can be used as a relationship. in different scenarios, there is no relationship between the dependency and the dependency, association indicates the relationship between two objects and does not disappear.


3. generalized VS implementation
For the comparison between implementation and generalization, generalization is the inheritance between classes, the inheritance between interfaces, and the implementation is the implementation of classes on interfaces. But from the aspect of drawing, there is no difference except a straight line and a dotted line. The relationship strength is also the same. Finally, compare the strength of several relationships:
Dependency <关联<聚合<组合<泛化=实现< strong>
III. Summary
Through comparative learning and examples, we can better understand the differences between several relationships. Legacy question: Is implementation a form of generalization?

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.