Classes as Types

First off, let us consider a class as a type. But what is a type? The notion of types is used for several different purposes in programming languages. Here are just a few of them. A type is a set of values with common attributes and operations. Thus, we speak of the integer type, and mean the set of integer values. A type is a behavioral specification. Thus, we say what operations we can perform with an Window object. A type is sometimes described a set of syntactic constraints; thus, for example, in C we can only use the subscript brackets on values that are of type Array. A type is sometimes described by a set of invariants; for example we might say a Stack is defined by the first-in-first-out invariants we associate with the idea.

To a compiler, a type is a protective mechanism that guards the bits in memory and tells us how they are laid out. Thus, for example, an integer has a different storage representation than does a real number.

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