(8) object-oriented design principle 4

Source: Internet
Author: User
: This article mainly introduces (8) the four principles of object-oriented design. if you are interested in PHP tutorials, please refer to them. I. replacement principle:
1. child classes must be replaced with their base classes and appear anywhere the parent class can appear.
2. problems to be solved by the LSP principle:
A. how to correctly design the inheritance
B. how to obtain the optimal hierarchy of inheritance
C. avoid the class hierarchy being designed into a situation that does not conform to the OCP principle
3. follow these principles:
A. All methods of the parent class must be implemented or overwritten in the subclass, and the derived class only implements the methods declared in its abstract class, but no redundant method definitions or implementations can be provided.
B. in the client program, only parent class objects should be used instead of subclass objects. In this way, you can bind data during runtime. (Dynamic polymorphism)

II. example:

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above section introduces (8) the four principles of object-oriented design, including content, and hopes to help those who are interested in PHP tutorials.

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.