What does Liskov Substitution Principle preserve? [duplicate]

独自空忆成欢 提交于 2019-12-11 20:10:56

问题


As I've read the substitution of objects of a concrete type by instances of a subclass of that concrete type must preserve a program's correctness, a program's invariants.

I'd like to know what exactly is meant by correctness and invariants of a program?


回答1:


Let's say you have a class Animal and someone asks you what it's supposed to do, what it can be used for, and how you can judge whether or not it is correctly implemented. Imagine that you gave a complete and detailed answer that didn't leave anything out. Now...

If class Cow is a subclass of class Animal, then everything in your answer about Animal must also apply to Cow.



来源:https://stackoverflow.com/questions/56330262/what-does-liskov-substitution-principle-preserve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!