Design principles of Ood

Source: Internet
Author: User
Design principle of design pattern-ood (1)-"open-close principle"
Design principle of design pattern-ood (2)-"The substitution principle of the Richter scale"
Design principle of design pattern-ood (3)-"dependency reversal principle"
Design principle of design pattern-ood (4)-"Interface Isolation principle"

Design principle of design pattern-ood (5)-"Synthetic polymerization multiplexing principle"



Liskov replacement principle (LSP)-barbara Liskov

: If the object of each type S O1, there is an object of type T O2, so that in all program p written for T, after replacing O2 with O1, the behavior function of program P is unchanged, then S is the subtype of T.


A popular explanation: A subtype can completely replace a parent type without any change in the behavior of the client that invokes the parent type.


A classic example of a violation of the Liskov substitution principle is the relationship between a square and a rectangle. Such an example of the principle of object design, has been wordy enough, here I will not repeat. The lesson of this example is that examples of inheritance in the real world cannot be applied entirely directly to the world of programs. However, as the reference of the design, many laws and laws of the real world, we still can not be ignored. For example whales and fish, should belong to what relationship. From a biological point of view, whales should belong to mammals, not fish. Yes, we can draw the same conclusion in the world of procedure. If the whale is to inherit the fish, it is completely against the principle of Liskov substitution. Because Fish is a parent, many traits are not available to whales, such as breathing through gills, and oviparous reproduction. So, do they have commonalities? Yes, they can all "swim" in the water, and from a programming standpoint, they all work together to implement an interface that supports "swimming" behavior.

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.