Is a relationship between has

Source: Internet
Author: User

 

By http://hi.baidu.com/zhjunxue/blog/item/dc1082817f56a8d09123d981.html

 

 

Is a relationship between has

This is understandable.

A car is a vehicle.
A car has an engine: An has-a engine.
Is-A is generally an inheritance relationship.
Has-A is generally a composite relationship.

Or, you can understand it in this way;

"Has a" link is a composite link, implemented by defining class attributes; "is a" link is an inheritance link, implemented through class inheritance

If you are sure that the relationship between the two objects is-a, you should use inheritance. For example, diamond, circle, and square are both shapes, then they should all inherit from the shape class rather than aggregate.

If you determine the relationship between two objects is has-a, you should use a combination at this time. For example, a computer is composed of displays, CPUs, hard disks, etc, then you should combine the display, CPU, and hard disk categories into computer categories, instead of inheriting from the computer class.

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.