里氏替换原则
Liskov Subsitution Principle, LSP :
- If for object o1 of type S there is an abject 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 of T.
- Functions that use pointers or reference to base classes must be able to use objects of derived classes without
knowing it.
- 子类必须完全实现父类的方法
- 子类可以有自己的个性
- 覆盖或实现父类的方法时输入参数可以被放大
- 覆写或实现父类的方法时输出结果可以被缩小
浙公网安备 33010602011771号