Several types of relationships in UML: inheritance, implementation, dependency, association, aggregation, and combination

Source: Internet
Author: User

Generalization (inheritance)

A class (called a subclass or sub-interface) inherits the functions of another class (called parent class or parent interface) and can add its own new functions, 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;

Realization (Implementation)

It refers to the function of a class to implement interface interfaces (which can be multiple). 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;

Dependency (dependency)

It can be simply understood that 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, if someone wants to cross the river and borrow a ship, the relationship between people and the ship is dependent. It is manifested in the Code layer, class B is used as a parameter by Class A in a method;

Association)

It represents a strong dependency between two classes or between classes and interfaces, such as my friends and I; this relationship is more dependent than the dependency relationship, with no dependency relationship. The relationship is not temporary and is generally long-term. In addition, the relationship between the two parties is generally equal, and the relationship can be one-way and two-way; it is manifested in the Code layer. For associated Class B, it appears in the form of class attributes in associated Class, it may also be that associated Class A references a global variable of the associated Class B;

Aggregation (aggregation)

Aggregation is a special case of association. It reflects the relationship between the whole and the part, that is, the relationship between has-a. At this time, the whole and the part can be separated, they can have their own lifecycles, some of which can belong to multiple objects, or share multiple objects, such as the relationship between computers and CPUs, and between companies and employees; it is manifested at the code level and is consistent with the Association, which can only be distinguished at the semantic level;

Composite (combination)

A combination is also a special case of association. It represents a contains-a relationship, which is stronger than aggregation, also known as strong aggregation; it also shows the relationship between the whole and the part, but the whole and the part are inseparable at this time, and the end of the overall life cycle means that part of the life cycle ends; for example, you and your brain; it is manifested at the code level and is consistent with the Association, which can only be distinguished at the semantic level;

There is no doubt about the relationship between inheritance and implementation. They reflect the vertical relationship between a category and a class, or between a class and an interface; the other four relationships reflect the reference and horizontal relationships between classes and classes, or between classes and interfaces, which is difficult to distinguish, there are many relationships between things. It is very difficult to prepare for positioning. As mentioned above, these relations are all semantic-level, so they cannot be fully differentiated from each other at the code level; however, in general, the following relationships show the following strengths and weaknesses:Combination> aggregation> association> dependency.

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.