As a concept, a superclass
is the parent of an object's Class. i.e. the Class one level higher in the Class hierarchy than the Class of the current object.
As a named method, it returns the name of the immediate superclass of the receiver.
e.g. it's definedin Squeak Smalltalk (and also in its derivatives, Pharo and Cuis) as
superclass
"Answer the receiver's superclass, a Class."
^superclass
In Dolphin Smalltalk, it's defined as
`superclass
"Answer a which is the receiver's immediate
superclass (or if none)."
^superclass'
But - every Class in the Class hierarchy is actually an instance of its parent class. So the Class that a given Class is an instance of, is the Class's MetaClass.
So, e.g.
aSortedCollection is an object - an instance of the Class SortedCollection.
SortedCollection is a Class - named Class 'SortedCollection' in the browsable Class hierarchy. Simultaneously, it is also an instance of a Metaclass - an anonymous Class which has a singleton object instance, which is a named Class. The named class is visible in the Class hierarchy, but the Metaclass (being anonymous) is much less visible. It is there so that Smalltalk
Smalltalk maintains a Metaclass hierarchy, i.e. a hierarchy of the Classes of the Classes. It's much less visible, as it's held as anonymous system objects, but you can find the top level of the Metaclass hierarchy in the Class browser. Both the Class Class
and the Class Metaclass
are to be found as sub-sub-classes of Class Behaviour
, itself a sub-class of Class Object
.
One reason that people say that "In Smalltalk, everything is an object" is because Class Object
is the root of all the other Classes and objects - it is at the very top of the object hierarchy, which contains the Class hierarchy, and the Metaclass hierarchy.
(It's generally at this stage that my brain begins to bleed out of my ears, but th following 3 points help push it all back in to my skull)
If you send the message anInstanceOfAClass class
- you'll get
the Class of the object anInstanceOfAClass returned.
If you send the message anInstanceOfAClass class superclass
- you'll get
the parent Class of the Class of the object anInstanceOfAClass returned.
If you send the message anInstanceOfAClass class class
- you'll get
the anonymous singleton Metaclass of the Class of the object anInstanceOfAClass returned.