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.