Object-oriented: understanding of inheritance, association, aggregation, combination, and dependency, and object-oriented Aggregation

Source: Internet
Author: User

Object-oriented: understanding of inheritance, association, aggregation, combination, and dependency, and object-oriented Aggregation

For example, please correct

1. Inheritance (generalization)

Link: a inherits from B, a is B

 

 

 

As shown in the figure, Benz, Audi, and Lamborghini all inherit from cars and all have wheels. They can both forward and stop.

Benz is a car.

Audi is a car.

Lamborghini is a car.

 

2. Association

Link: a has B

 

3. Aggregation

Link: a has B

The whole part is not responsible for the destruction of local objects, and the lifecycle of the two is not associated.

4. Combination

Link: a has B

The whole part is responsible for the destruction of local objects.

 

 

5. Dependency

Link: a use B

 

 

Inheritance represents the vertical relationship between classes.
The other four types reflect the horizontal relationship between classes.


Coupling Strength:
Dependency <join <aggregation <combination


In terms of semantics
Inheritance (A is B)
Association, aggregation, and combination (A has B)
Dependency (A use B)


When combination and dependency are combined, inheritance can be replaced.
Combination + dependency (Object-based) vs inheritance (object-oriented)

 

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.