Summary of synthesis and inheritance learning

Source: Internet
Author: User

Regardless of inheritance or compositing, we can create a new type based on an existing type. But in typical cases, we use compositing to implement the existing type of "regenerate" or "reuse" as part of the new type of foundation implementation process. However, if you want to implement the "regeneration" of an interface, you should use inheritance. Because a derived or derived class has an interface to the underlying class, it can be "traced back" to the underlying class. This is crucial to the question of the polymorphism that is to be described in the next chapter.

Although inheritance is particularly emphasized in object-oriented programming, it is best to consider the use of synthetic techniques when actually starting a design. The use of inheritance techniques should be considered only when it is particularly necessary (the next chapter will cover this issue). Synthesis appears more flexible. However, by applying some inheritance techniques to your own member types, you can change the type of those member objects accurately at runtime, thereby altering their behavior.

While for rapid project development, code regeneration through compositing and inheritance is a great help. But before allowing other programmers to rely entirely on it, it is generally desirable to redesign their class structure. Our ideal class structure should be that each class has its own specific purpose. They cannot be too large (such as the integration of too many functions, it is difficult to achieve its regeneration), nor too small (caused by their own use, or can not add new features). The final implementation of the class should be able to easily regenerate.

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.