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

Reverse polymorphism

Polymorphism says we can assign a value from a child class to an instance of the parent class, but can this assignment then be reversed? Under what conditions?

var
	pet : Mammal;
	fido : Dog;
	felice : Cat;
begin
	pet := fido;	// legal
	fido := pet;	// is this legal? 
end;

This is known as the problem of reverse polymorphism.
Intro OOP, Chapter 10, Slide 8