views:

250

answers:

3

I new to OOP, but with a "procedural" background.

I'm currently trying to get my head around OOP via GNU Smalltalk and Lovejoy's "Smalltalk: Getting The Message".

I'm confused as to the the heck the metaclass and Metaclass class are, vs superclass. I can see the inheritance flow of superclass -> class -> subclass; but I don't see how/where metaclass fits in. TIA...

+4  A: 

There are actually two levels of inheritance: instance inheritance and class inheritance.

Smalltalk has a special scheme that makes it possible to pass around classes as objects. That means classes are also objects in their own rights. The metaclass is "simply" the class of the class object.

It doesn't interfere with normal instance inheritance, so it doesn't fit anywhere in the superclass -> class -> subclass diagram you used.

zneak
@ zneak -> "The metaclass is "simply" the class of the class object."I thought that the superclass was "the class of the class object". That's my question really - what's the diff between superclass and metaclass?
duke
"There are actually two levels of inheritance: instance inheritance and class inheritance."From this formulation, I'd guess you're confusing inheritance and instanciation…
Damien Pollet
This is really what I meant. Subclasses can override what we'd call static methods in other languages.
zneak
+3  A: 

There is an excellent description in the free online book Pharo by Example, Chapter 13 (Classes and metaclasses). The things explained in this chapter are common to all Smalltalk implementations.

Lukas Renggli
Thanks for the link! Seems to be what I'm looking for.
duke
+3  A: 

There are two different relations in class-based OO: instanciation and inheritance.

Instanciation is the relation between an object and its class, the new keyword, etc. Usually it's implemented by a pointer in the low-level representation of any object. In Smalltalk, anObject class traverses this pointer; it also happens that classes are also objects, and classes of classes are called metaclasses, but this is the same relation as with instances.

Inheritance is a relation between classes. You can go from a class to its superclass by doing aClass superclass, and keep doing so until you get to the class Object. In Smalltalk, the superclass pointer is just an instance variable defined on any class, and the superclass message is a normal accessor.

Damien Pollet