Software Design----Liskov replacement principle (LSP)

Source: Internet
Author: User

Definition of the Liskov substitution principle: If a software entity is using a base class, it must be applied to its subclasses, and the difference between the base class object and the subclass object cannot be detected at all.

1) How to understand the above concept? Is that the subtype of our programming can completely replace the parent type without any change in the behavior of the client that invokes the parent type.

2) What is the meaning of this principle? This principle is mainly to ensure that the code is open to the extension, as long as the subclass can completely replace the behavior of the base class, the new specific subclass in the overloaded parent class, will not have any adverse effect on the customer code, thus implementing the extension open.

At design time, we can use this principle to determine whether the subclass of our design is reasonable. Think: squares are designed into rectangular subclasses, OK?

Software Design----Liskov replacement principle (LSP)

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.