Advantages and disadvantages of Inheritance

Source: Internet
Author: User
Advantages and disadvantages of Inheritance
Advantages
New implementations are easy, because most of them are inherited.
It is easy to modify and extend existing implementations.

Disadvantages
The encapsulation is broken because the basic class exposes implementation details to the subclass.
White box reuse, because the internal details of the base class are usually visible to the subclass.
When the implementation of the parent class changes, the subclass may be changed accordingly.
The implementation inherited by the parent class cannot be changed at runtime.
It can be seen that the combination has more flexibility and more stable structure than the inheritance. Generally, the combination should be given priority. Only

Inheritance is considered only when the following conditions are met:
Subclass is a special type, not just a role of the parent class.
Subclass instances do not need to be converted into objects of another class.
Subclass extension, instead of overwriting or disabling the function of the parent 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.