Introduction to OOP Chapter 19: Container Classes : next previous audio real text

Using Classes as Objects to do Type Checking

In languages in which classes are objects, and have the ability to tell if an object is an instance, the container can hold the class object that represents its type:
var
	stack : TStack;
	aCat : TCat;
	aDog : TDog;

begin
		// create a stack that can hold only TCat values
	stack := TStack.Create (TCat);
	stack.push (aCat); // ok
	stack.push (aDog); // will raise exception
	...
end

Allows typing errors to be caught on insertion, but uses more space and time.
Intro OOP, Chapter 19, Slide 07