Several relationships between classes and classes

Source: Internet
Author: User
Tags dashed line

Inheritance relationship inheritance refers to the ability of a class (called a subclass, sub-interface) to inherit the functionality of another class (called the parent class, parent interface) and to increase its own new functionality. Inheritance relationships in Java are clearly identified by keyword extends and are generally not controversial at design time. In UML class diagram design, inheritance is represented by a solid line with a hollow triangular arrow, from a subclass to a parent class, or a sub-interface to a parent interface.


Realization of the implementation of the relationship refers to a class implementation of the interface interface (can be multiple) function, implementation is the most common relationship between the class and interface. In Java, this type of relationship is clearly identified by the keyword implements, which is generally not controversial at design time. In the UML class diagram design, the implementation is represented by a dashed line with a hollow triangular arrow, from the class to the implemented interface.


third, the dependence of a simple understanding of the dependency is that a class A used to another class B, and this use of the relationship is contingency, temporary, very weak, but the change of Class B will affect the Class A. For example, if someone wants to cross the river, they need to borrow a boat, and the relationship between the man and the ship is dependent. At the code level, for Class B as a parameter, Class A is used in a method. In UML class diagram design, a dependency relationship is represented by a dashed line with an arrow pointing to Class B.


Correlation Relationship is a strong dependency of the semantic level between two classes, such as me and my friends, the relationship is more than dependence, the contingency of no dependence, the relationship is not temporary, generally long-term, and the relationship between the two sides is generally equal. Associations can be one-way, two-way. At the code level, the associated class B appears in the association Class A as an attribute of the class, or the association Class A refers to a global variable of the type being associated with Class B. In the UML class diagram design, the association relation is represented by the arrow solid line that the association Class A points to the associated class B, and the roles and multiplicity tags of the two sides can be labeled at both ends of the association.


Polymerization Relationship aggregation is a special case of association, which embodies the relationship between the whole and the part, that is, the relationship between the has-a. At this point, the whole and the parts are separable, they can have their own life cycle, some can belong to more than one whole object, or can be shared for multiple whole objects. such as computer and CPU, the relationship between the company and employees, such as an aircraft carrier formation including the sea and air mother ship, the protection of ships, ship-borne aircraft and nuclear power attack submarine. Performance at the code level, and the association relationship is consistent, only from the semantic level to differentiate. In the UML class diagram design, the aggregation relationship is represented by a hollow diamond plus a solid line arrow.


The combination of combination relationship is also a special case of association, it embodies a kind of contains-a relationship, which is stronger than aggregation, also known as strong aggregation. It also embodies the relationship between the whole and the part, but at this time the whole and the part are not divided, the whole life cycle end also means that part of the life cycle end, such as human and human brain. Performance at the code level, and the association relationship is consistent, only from the semantic level to differentiate. In the UML class diagram design, the composition relationship is represented by a solid diamond plus solid line arrow.


Vii. Summary for the inheritance, the realization of these two relations have little doubt, they embody a class and class, or class and interface between the vertical relationship. The other four kinds of relationships embody the class and class, or the reference between the class and interface, transverse relationship, is more difficult to distinguish, there are many things between the relationship to be accurate positioning is difficult. As mentioned earlier, these four relationships are semantic level, so from the code level does not completely distinguish between the various relationships, but in general, the following relationships are manifested by the degree of strength: Combination > Aggregation > Association > dependency.

From: http://www.cnblogs.com/liuling/archive/2013/05/03/classrelation.html

Several relationships between classes and classes

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.