Dependency, association, aggregation, combination

Excerpt from: http://www.iteye.com/topic/632059

rely on

It can be simply understood that one class a uses another class B, and this use relationship is accidental, temporary and very weak, but the change of class B will affect class A;

For example, if someone wants to cross the river and needs to borrow a boat, the relationship between people and boats is dependence; At the code level, class B is used as a parameter by class A in a method method method.

relation

It embodies a strong semantic dependency between two classes, or between classes and interfaces, such as me and my friends; This relationship is stronger than dependence, and there is no contingency of dependence

The relationship is not temporary, but generally long-term, and the relationship between the two sides is generally equal, and the relationship can be one-way and two-way; At the code level, it is associated class B with class attributes

The form appears in association class A, or association class A may refer to a global variable of type associated class B.

polymerization

Aggregation is a special case of association relationship, which embodies the relationship between the whole and part and ownership, that is, the relationship of has-a. at this time, the whole and part are separable, and they can have their own characteristics

In the life cycle, a part can belong to or be shared by multiple overall objects; For example, the relationship between computer and CPU, the company and employees, etc; At the code level, it is related to the relationship

Consistent, can only be distinguished from the semantic level.

combination

Combination is also a special case of association relationship. It embodies a kind of contains-a relationship, which is stronger than aggregation, also known as strong aggregation; He also embodies the relationship between the whole and the part,

But at this time, the whole and the part are inseparable, and the end of the life cycle of the whole means the end of the life cycle of the part; Like you and your brain; At the code level, it is consistent with the relationship,

It can only be distinguished from the semantic level.

---------The strength of the latter relationships is as follows: combination > aggregation > Association > dependence

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>