[squeak-dev] On class/metaclass coupling

Igor Stasenko siguctua at gmail.com
Tue Dec 8 11:49:30 UTC 2009


For people who think that we should not revise the class/metaclass
coupling in Squeak,
just ignore this topic and consider it as a rant :)

For those, who interested why i think its not a perfect from
object-oriented point of view, continue reading.

Ok. Lets start from basics.

A classes, in smalltalk is a first class objects, which one of its
strong sides, comparing to other languages.
Since each object has a class, we also need an object which reflecting
the class itself, and hence the metaclass.

But then, each class could have as many instances as it likes to, isnt?
But here the contradiction, which drives me nuts, when i looking at
Metaclass definition - 'thisClass' ivar.

This implies that any metaclass could have only a single instance - class.

Metaclass>>new
	"The receiver can only have one instance. Create it or complain that
	one already exists."

	thisClass class ~~ self
		ifTrue: [^thisClass := self basicNew]
		ifFalse: [self error: 'A Metaclass should only have one instance!']

but hey..
what you suppose to do with things like:

SomeClass clone

?
I am trying to understand, why do we need this inconsistency by
enforcing such a rigid rule.

Like, how often you may need to determine a 'sole' instance of the
class, or all instances?
And why it needs to be so fast by keeping a direct reference to it?

System browser could live well without it.
Altering the metaclass definition? Well, iterate over all instances
indiscriminately - using same mechanism as usual class doing for own
instances.
So, it is strange to me, why do we need such tight coupling..

Is anyone having insights about it?

-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list