Implications of Classes for Types

When inheritance and polymorphic variables are introduced, each of the different views of types described on the previous slide becomes more problematic. For example, at the time either the programmer or the compiler sees a variable declaration, they may not know the actual final type that a variable will hold. Thus, for example, we have seen how polymorphism complicates memory management, since we cannot tell how much memory a variable will hold. We have seen how subclasses can override a method from a parent class, and perhaps in so doing change an important aspect, such as running time, thereby defeating the principle of substitutability. Because of this, the testing of a program, or even proofs of correctness, may no longer be valid if a substitution of a child class value in a parent class variable takes place.

Thus, our notion of a class does not exactly match the conventional view of a type.

[audio] [real] Text to accompany slide5, in Chapter 20 of An Introduction to Object-Oriented Programming