设计原则-里氏替换原则

来源:互联网 发布:淘宝能卖军用品吗 编辑:程序博客网 时间:2024/05/16 15:03

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 substituted for o2 then S is a subtype of T.


包含4层含义:

1.子类必须完全实现父类的方法

2.子类可以有自己的个性

3.覆盖或实现父类的方法时输入参数可以被放大

4.覆写或实现父类的方法时输出结果可以被缩小