0

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?

beginpluses
  • 497
  • 2
  • 9

1 Answers1

0

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.

Matt Timmermans
  • 53,709
  • 3
  • 46
  • 87