Dependency, association, aggregation, and composition relationships between classes and classes

Source: Internet
Author: User

Original

This one is quite in place.

I. The relationship of succession 
inheritance refers to the ability of a class (called a subclass, sub-interface) to inherit the functionality of another class (called a 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.
<ignore_js_op>

Ii. Realization of the relationship 
implementations refer to a class class that implements the interface interface (which can be multiple), and implementation is the most common relationship between classes and interfaces. 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.
<ignore_js_op>

iii. Dependency Relationship 
simply understood, dependency is that a class A uses another Class B, which is accidental, temporary, and very weak, but changes in class B affect 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.
<ignore_js_op>

Iv. Related Relationships 
correlation is a strong dependency between the semantic levels of the two classes, such as me and my friends, who are more dependent and less dependent on the contingency, the relationship is not temporary, generally long-term, and the relationship between the two are 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.
<ignore_js_op>

v. The relationship of aggregation 
aggregation is a special case of association, which embodies the relationship between the whole and the part, that is, the relationship of 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.
<ignore_js_op>

vi. combination of relationships
The combination is also a special case of the association relationship, which embodies a 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.
<ignore_js_op>
Seven . Summary  
there is little doubt as to the inheritance and implementation of the two relationships, which represent a class and class, or a vertical relationship between a class and an interface. 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.

(to) dependencies, associations, aggregations, and combinations 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.