Object-oriented inheritance and composition

Source: Internet
Author: User

The advantage of object-oriented is the reuse of classes. Inheritance and polymorphism are the reuse of classes, a class-level reuse, and a method-level reuse. What are the similarities and differences between the two references to inheritance? is PHP really polymorphic? If not, then why not? What is the difference between some words and the polymorphism in other languages?

Inheritance and composition are all ways to improve code reusability. When you design a model, you can identify the composition and inheritance relationships between classes by language. From the perspective of method reuse, if there are many identical codes and methods in two classes, you can abstract a father from these two classes, provide a public method, and then two classes as subclasses, providing a personalized approach. At this point inheritance semantics are better. There are not so many restrictions on the combination. Classes between combinations can be relational (embodied as code reuse) with little or no relationship. However, in programming, the trade-offs between inheritance and composition are often not straightforward enough to determine whether they should be inherited or combined. Do you have any criteria? Yes, the standard is low coupling. Coupling is a measure of the degree of interconnection between different modules within a software structure, which is the dependency between different modules. Between the low-coupling batch module and the module, as far as possible to make the module independent existence, the module and the interface between the module as small and simple. Decoupling is to release the dependencies between the modules and modules.

Object-oriented inheritance and composition

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.