Introduction to OOP: Chapter 10: Subclasses and Subtypes [next] [previous] [audio] [real] [text]

Polymorphic Variables

Object-Oriented concepts introduce a new twist on the static/dynamic distinction.

The is-a relationship asserts that an instance of a child class is in all important respects a representative of the parent class.

Thus, a value of a child class should be able to be assigned to a variable of the parent class. The reverse, however, is not generally permitted.

var
	pet : Mammal;
	fido : Dog;
	felice : Cat;
begin
	pet := fido;	// legal
	pet := felice;	// legal
	fido := pet;	// illegal !
Intro OOP, Chapter 10, Slide 5