Thanks type and gentle class

Type and class are not interchangeable terms, but two carefully distinguishable object-oriented concepts

1 2 Page 2
Page 2 of 2

Let's closely examine Gosling's statement. Recall that a class defines a single type, and that object creation requires a single class. Even though class inheritance may combine multiple modules along a single implementation inheritance chain, conceptually, object creation occurs using a single class blueprint. Importantly, the blueprint brands the object, and this class branding does not change during the object's lifetime. The class used to create an object determines the object's implementation code. The object's structure does not subsequently change.

Stating that "objects have class" rather than type adheres to the article's distinction. The class concept primarily focuses on modularization and implementation code reuse. Class definitions provide the implementation code associated with a runtime object. So at runtime, an object has class, not type.

Nevertheless, when a class defines implementation code, it also defines a type. That one-to-one correspondence, resulting from the dual roles played by a class, leads to a natural association of an object with a type, namely the type defined by the class used to instantiate the object. Though I agree with the spirit of Gosling's assertion, I accept and practice referring to an object's type. That does not compromise the important distinction between type and class that lies in separating interface and implementation.

Conclusion

Type and class are not indistinguishable. Types define module boundaries. That allows compile time type-checking to ensure the proper interaction with and between runtime objects. Classes define code implementation. At runtime, objects obtain their implementation marching orders from class definitions.

The distinction between type and class also plays an important part in understanding inheritance. Both class and interface declarations affect a system's type inheritance hierarchy. By supporting multiple type inheritance, a supertype reference can attach to various subtype objects. Only class declarations, however, affect a system's implementation inheritance. Single class inheritance ensures a runtime object has a single implementation strategy for each runtime message it may receive.

An understanding of the distinction between type and class facilitates the separation of interface and implementation. When you want to know what an object can do, think type. When you want to know what an object will do, think class.

Wm. Paul Rogers is an application architect at Lutris Technologies, where he builds computer solutions utilizing Enhydra, the leading open source Java/XML application server. He began using Java in the fall of 1995 in support of oceanographic studies conducted at the Monterey Bay Aquarium Research Institute, where he led the charge in utilizing new technologies to expand the possibilities of ocean science research. Paul has been using object-oriented methods and technologies for over nine years.

Learn more about this topic

1 2 Page 2
Page 2 of 2