浅析设计模式-里氏替换原则
里氏替换原则的英文名称是 Liskov Subsitution Principle,简称 LSP。
定义
第一种定义,也是最正宗的定义: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is subsituted for o2 then S is a subtype T.(如果对每一个类型为S的对象o1,都有类型为T的对象o2,使得以T定义的所有程序P在所有的对象o1都代换为o2时,程序P的行为没有发生变化,那么类型S是类型T的子类型。)
第二种定义: Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it.(所有引用基类的地方必须能透明地使用其子类的对象)。