How does Object (or ProtoObject) implement new?
Hi
Object does ****NOT**** implement new. new is a ****class**** behavior. In fact one of the major difference between the class Object and the class Class is that Class knows how to create instance, Object not.
What you should remember in only one principle: (thanks uniformity of Smalltalk)
When one sends a message to an instance First we go to its class to look for a method Second we follow the inheritance link if the method was not found
So aBox move => Box look for move
aBox instVarAt: => BoX look for instVartAt: => Then Object look for instVarAt:
What you should notice is THIS IS THE SAME FOR CLASS
Box new => Box class (the class of BOX) look for new => Then Object class look for new => you continue to go up in the inheritance chain => Then .... Behavior look for new.
IF you want to know more look in my Smalltalk lectures and reflective lectures notes.
on 3/29/01 6:48 PM, Karl Wilson at khwilson@bigfoot.com wrote:
Merrily working away on the _Squeak OO Design with Multimedia Applications_ book. Joe the Box. I get curious about how "new" is implemented.
How does Object (or ProtoObject) implement new?
When you write Box>>new (Box is a subclass of Object):
new ^super new initialize.
where is the new that it is finding?
I found Behavior>>new, which calls a primitive, which seems a likely possibility, but I can't see how Object uses it?
What am I missing? I realize that this is the most basic of the basic. It is highly unnerving to have it be such a mystery. I mean if you are supposed to be able to find the implementation of almost anything in the system, shouldn't you be able to easily see how Object implements new?
8?(
Karl (revealing the depths of newbieness)