UML relationship: Inheritance/generalization, implementation, dependency, association, aggregation, combination of association and difference, uml2016-07-12

Source: Internet
Author: User

UML relationship: Inheritance/generalization, implementation, dependency, association, aggregation, combination of association and difference, uml2016-07-12

These relationships are described respectively:

UML relationships: the relationships and differences between inheritance (generalization), implementation, dependency, association, aggregation, and combination

I. Differences in symbols

Ii. Differences and Contacts

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. Inheritance is the most common relationship between classes or interfaces. in Java, such relationships are identified by the keyword extends, which is generally not controversial during design.

[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. A class implements the interface (which can be multiple) function. Implementation is the most common relationship between classes and interfaces. in Java, such a relationship is identified by the keyword implements, it is generally not controversial during design;

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

3. Dependency(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. A Class A uses another class B, and this relationship is contingent, temporary, and very weak, but changes in Class B will affect A. For example, A teacher wants to teach, the relationship between the teacher and the class is dependent;

[Code representation]: local variables, method parameters, or calls to static methods

[Arrow and direction]: a dotted line with an arrow pointing to the user

4. Join (Association)

[LINK]: a link between a class and a class. It allows a class to know the attributes and methods of another class. A strong dependency between two classes or classes and interfaces at the semantic level. This relationship is more powerful than dependency, and is generally long-term, and the relationship between both parties is generally equal. For example, the relationship between teachers and students, 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/global variable

[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:

5. Aggregation)

[Aggregation relationship]: A special case of association. It is a strong association. aggregation is the relationship between the whole and the part, and the part can exist independently from the whole. They can have their own lifecycles, and some can belong to multiple overall objects, it can also be shared among multiple objects, such as the relationship between the computer and the CPU, the company and the employees, the car and the tires. It is manifested in the Code layer and is consistent with the relationship, it can only be distinguished from the semantic level;

The aggregation relationship is also implemented using instance variables. from the java syntax, It is not out-of-the-box and aggregated. in an association, two classes are at the same level, while in an aggregation relationship, two classes are at an unequal level. One Class indicates the whole, and the other class indicates the part.

[Code embodiment]: member variable/global variable

[Arrow and direction]: solid line with hollow diamond. The diamond points to the whole.

6. Combination(Composition)

[Composite relationship]: it is also a special case of association. It is a stronger link than an aggregation relationship, also known as forced aggregation. It also reflects the relationship between the whole and the part, however, at this time, the entire and part of the lifecycle cannot be divided. The end of the overall lifecycle means that part of the lifecycle ends. For example, the relationship between the company and the Department is the whole and the part, if no company exists, the team merging relationship cannot be shared.

The combination is almost the same as aggregation. The only difference is that "part" cannot be separated from "whole". That is to say, "part" cannot have a longer life cycle than "whole.

[Code embodiment]: member variable/global variable

[Arrow and direction]: solid line with solid diamond. The diamond points to the whole.

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:

Iii. comprehensive comparison

1. Aggregation and combination

(1) Aggregation and combination are a combination, but they only have an additional meaning of the whole-part.

(2) Different parts have different lifecycles.

In the aggregate relationship, the whole part does not have the life cycle of the part, so the part will not be deleted when the whole part is deleted. In addition, multiple parts can share the same part.

In the composite relationship, the whole part has the life cycle of the part. Therefore, when the whole part is deleted, the part will be deleted. In addition, multiple parts cannot share the same part at the same time.

(3) The aggregation relationship is "has-a", and the combination relationship is "contains-.

2. Association and aggregation

(1) It is represented at the code level and is consistent with the association. It can only be distinguished at the semantic level.

(2) The difference between Association and aggregation is mainly in terms of semantics. The two objects associated are generally equal. For example, if you are a friend of mine, aggregation is generally not equal.

(3) Association is a structured relationship, that is, an object is associated with another object.

(4) Association and aggregation depend on the problem domain. For example, tires must be combined in the automobile field, it makes no sense when it leaves the car. However, in the shops where tires are sold, even if the tires leave the car, it makes sense, and this can be aggregated.

3. Association and dependency

(1) A strong dependency between two classes or between classes and interfaces, such as my friends and I; such a relationship is more dependent than the dependency, and does not have any dependency relationship. The relationship is not temporary and generally long-term, and the relationship between the two parties is generally equal.

(2) In dependency relationships, we can simply understand that A class A uses another class B, and this relationship is contingent, temporary, and very weak, but changes in Class B will affect.

4. comprehensive comparison

These relationships are semantic-level, so they cannot be fully differentiated from each other at the code level. However, in general, the strength and weakness of these relationships are as follows:

Combination> aggregation> association> dependency

 

The two blogs are combined as follows:

Http://blog.sina.com.cn/s/blog_94c2c46a0102vaiz.html

Http://blog.csdn.net/wzjking0929/article/details/51803110

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.