CSC/ECE 517 Fall 2007/wiki2 6 mxz
Assignment 2 - Topic 6
Type v.s. Class
Survey the differences on type vs. class in object-oriented languages. Often, the distinction is that class pertains to an object, whereas type pertains to a variable. Consider the distinction between the two terms in several different programming languages. Cover the differences between type and class, from type-theoretic definitions to practical aspects.
Definitions of Type and Class
Types limit the values that a variable can hold or that an expression can produce, limit the operations supported on those values, and determine the meaning of the operations. Types are corresponding to values through variables, expressions.
A class is exactly the combination of a type, a (possibly trivial) constructor and optionally a subtyping relation. Also, classes are corresponding to objects.
Class pertains to an object, whereas type pertains to a variable. The primary difference is that "type" is generally a compile-time concept. The class of an object, though, exists and is important at runtime, primarily in polymorphism, and in the behavior of casting operations. Of course, in OOP languages, classes are types, while most types are not classes. In pure object languages, by opposition (e.g. Smalltalk, Scala, perhaps Python), every type maps to a class.