Confusion over basic Array new:

Eliot & Linda elcm at pacbell.net
Thu Sep 17 18:41:06 UTC 1998


guzdial at cc.gatech.edu wrote:
> 
> Sorry for what's probably a silly question, but I'm trying to figure out why the statement:
> anArray := Array new: 10.
> works.  Array doesn't have a class method new:.  Neither does ArrayedCollection, SequentialCollection, Collection, nor Object.  So where's the method that is being called on this message?

You should be searching through
	Array class
	ArrayedCollection class
	SequentialCollection class
	Collection class
and	Object class

Then you find that Object class's superclass is not nil, since its a
Class, but Class.  So the search is actually:

	Array class
	ArrayedCollection class
	SequentialCollection class
	Collection class
	Object class
	Class
	ClassDescription
	Behavior (voila!)
	Object

Ignoring proxy objects, Object is the root of all objects, and Object
class is the root of all class objects.  Object doesn't have any
superclasses because it is the root of the hierarchy of classes.  Object
class does have a superclass sicne it is the root of the metaclass
hierarchy and inherits all the appropriate class behaviour from Class.

Object conveys behaviour to its instances.  Object class and subclasses
implement the behaviour of their instances, the named classes, just as
the named classes implement the behaviour of their instances, the
"ordinary" objects.  But Object class and all the other metaclasses have
their own behaviour which must be implemented by some class.  This class
is Metaclass.  Metaclass inherits from ClassDescription, because a
metaclass also has methods, a comment and an organization.  But
metaclasses share the class pool and shared pools with their sole
instance, their named class.  Hence its Class which implements class and
shared pools.  metaclass implements having a named class.

Of course, Metaclass must have a metaclass, Metaclass class, and this,
just like all other metaclasses, is an instance of Metaclass.  This is
the circularity that terminates the class meta-regress.  Don't let
anyone tell you it doesn't make sence.  It makes perfect sense once you
understand it.  But don't let any one tell you its simple either :)

There's a great diagram of this in the blue/purple book.  You can also
use e.g. a structured drawing inspector like HotDraw to build the
diagram yourself.  Just keep clear the class/instance distinction and
it'll become clear.
_______________,,,^..^,,,_______________
Eliot Miranda, ParcPlace





More information about the Squeak-dev mailing list