The relationships between classes

Source: Internet
Author: User

The relationships between classes and classes are:

1. Related relations;

2, the combination of relations;

3, the aggregation relationship;

4, the dependence relationship;

5, inheritance relations;

6, the realization of the relationship;

Among them, the combination relation and the aggregation relation are the special correlation relations.

Association relationship:

A->b a association B is a one-way association, if b->a, it forms two-way association;

Semantics: a knows a B

Code form:

Class a{

B *m_b;

}

The combination relationship and the aggregation relationship are the same in the code form and the correlation, but the semantics are different:

The semantics of combinatorial relationships: A contains a B, A is dead, B is not alive;

The semantics of the aggregation relationship: A contains a B, A is dead, B can live;

Inheritance Relationship:

Semantics: B is a kind of a

Code form:

Class B:a

{

}

In the realization relation, the implementation is often an interface (interface), the code form is the same as the inheritance relation;

Dependency Relationship:

Semantics: A uses a B

Code form:

Class a{

Method (B &b);

}

The relationships between 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.