Metaclass - Alternative Definition

Alternative Definition

The classical definition of a metaclass as a class whose instances are classes poses several problems:

  • All classes without instances would pass the definition, so that they become metaclasses by vacuous truth.
  • If the "instance-of" term is used in the non-strict sense, allowing indirect instances, the inheritance root can be wrongly recognized as a metaclass.
  • The requirement that a metaclass is a class disallows (or at least complicates) a uniform view of the Ruby and Smalltalk-80 object model.

The following alternative definition, based on the eigenclass model, avoids all the above problems.

  1. The metaclass root is the class of the inheritance root.
  2. An object is a metaclass if it is an inheritance descendant of the metaclass root.

In (2), inheritance descendant is meant in the non-strict sense – including the metaclass root itself. The definition applies to all of Ruby, Python, Scala, Java, Smalltalk and CLOS, although in the case of the latter two languages care must be taken as to what is meant by class of in (1). Unfortunately, the introspection methods class (in Smalltalk) and class-of (in CLOS) are misleading here.

For Objective-C, a modified definition has to be used due to the multiplicity and degeneracy of inheritance roots.

Read more about this topic:  Metaclass

Famous quotes containing the words alternative and/or definition:

    Education must, then, be not only a transmission of culture but also a provider of alternative views of the world and a strengthener of the will to explore them.
    Jerome S. Bruner (20th century)

    According to our social pyramid, all men who feel displaced racially, culturally, and/or because of economic hardships will turn on those whom they feel they can order and humiliate, usually women, children, and animals—just as they have been ordered and humiliated by those privileged few who are in power. However, this definition does not explain why there are privileged men who behave this way toward women.
    Ana Castillo (b. 1953)