green griffin.gif (31989 bytes)

 

A 'type' is a set of values, and a set of operations on those values, applied to an object. Types can be useful for a number of reasons

  • In general, by 'typing' a program becomes more reliable. Static type-checking can insure 'type-safe' programming by eliminating the need for objects to protect themselves from unexpected messages.
  • Well 'typed' programs are then more readable, because types provide a kind of documentation.
  • Types enable optimisations, therefore an un-typed program may be less efficient than a typed one.

Superficially, an object type seems to be the same thing as an object class, and in many typed object-oriented languages with class-based inheritance (such as Simula, C++ and Eiffel) no distinction is made between classes and types. In other words, the type of an object is its class, the subtype relation is uniquely determined by the class hierarchy, and subtype polymorphism is the same as subclass polymorphism. This approach improves performance but the flexibility can lead to insecure type-systems. On the other hand, by putting some restrictions on inheritance, we can get static type-checking, but then there is a loss in flexibility which is significant for system development.

It is possible however, to separate the notion of classes from the notion of type, allowing many classes per type while still maintaining reasonable type-safety. By separating type from class, replacing objects must satisfy the operations or type constraints of a polymorphic object (subtype polymorphism) but are not required to do so by an inheritance relation (subclass polymorphism), as is typical in most object- oriented programming languages.

Dropping this restriction is somewhat less type- safe, because accidental matches of method signatures can occur, calling for greater care in use. In other words,  a possible loss of semantic integrity and similarity is contrasted with greater power and flexibility.

Some observers  propose an approach based on explicit interfaces and interface containment. In this system of object interfaces, one type is considered a subtype of another if some subset of its interface is identical to that of the second. The primary goal is to allow interface compatibility to be checked at compile time, eliminating the possibility of certain run-time errors,  while preserving the power and flexibility of un-typed object-oriented languages (like Smalltalk).

In  this system class-based inheritance is strictly a reusability mechanism for sharing behaviour between objects, not to be confused with subtyping. For example, two classes may be equivalent as types, though neither inherits anything from the other. So class hierarchies are not  the same as type hierarchies, although the similarities may overlap.

Back To Top

 

VISIT AN AREA IN OzEdweb

Technophile.City    The.Time.Machine     The.Tree.House    Lessons.Index      Assessment.Instruments     Maps     Power.Point     Proforma     Links     Gallery     Games     Humour      Prizes     WebRings     Soapbox     Search.Engines     Site.Map

.

             Search OzEdweb By Keyword   

.CLICK ME TO VIEW FRAMES ALL RIGHTS RESERVED  OZEDWEB-©-VIRTUAL OZ  HOME..