Liskov替代原则保留什么? [英] What does Liskov Substitution Principle preserve?

查看:88
本文介绍了Liskov替代原则保留什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读到具体类型的对象被该具体类型的子类的实例替换时,必须保留程序的正确性,即程序的不变性.

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?

推荐答案

假设您有一个class Animal,有人问您该做什么,该做什么用以及如何判断是否它已正确实施.想象一下,您给出了完整而详细的答案,但没有遗漏任何内容.现在...

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...

如果class Cowclass Animal的子类,那么答案中有关Animal的所有内容也必须适用于Cow.

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

这篇关于Liskov替代原则保留什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆