What is the difference between Type and Class?

yesraaj picture yesraaj · Jan 22, 2009 · Viewed 63.1k times · Source

What makes a type different from class and vice versa?

(In the general language-agnostic sense)

Answer

yesraaj picture yesraaj · Apr 20, 2009

The following answer is from Gof book (Design Patterns)

An object's class defines how the object is implemented .The class defines object's internal state and the implementation of its operations.

In contrast, an object's type only refers to its interface - a set of requests to which it can respond.

An object can have many types, and objects of different classes can have the same type.

//example in c++
template<typename T> 
const T & max(T const & a,T const &b)
{
return a>b?a:b;  //> operator of the type is used for comparison
}

max function requires a type with operation > with its own type as one of it interface any class that satisfies the above requirement can be used to generate specific max function for that class.