Squeak 3.8/3.9 and Behavior class new

Klaus D. Witzel klaus.witzel at cobss.com
Sun May 14 11:24:41 UTC 2006


Hi Alex,

on Sun, 14 May 2006 13:04:16 +0200, Ayou <Alexandre.Bergel at cs.tcd.ie>  
wrote:

>> You would like to have
>>
>> Behavior>>new
>> 	
>>  	^ self basicNew initialize.
>>
>> Behavior>>initialize
>>
>> 	self methodDictionary: self emptyMethodDictionary.
>> 	self superclass: Object.
>> 	self setFormat: Object format.
>> 	^ self
>
> I just tried and it works. I also tried to break it when creating  
> subclasses, but I was not successful.
> Let's assume a class A, for which:
> A class>>initialize
> 	" do nothing"
>
> I was wondering why I can still create a subclass of A.

The hack looks like it was necessary when migrating the image to Traits.  
But now Traits have arrived at 3.9b and Behavior>>initialize can again  
behave <grin> like a regular citizen.

> Actually, when a subclass is created, Behavior>>new is called on the  
> class Metaclass. Then, this instance of Metaclass is initialized with a  
> superclass and an empty dictionary (ClassBuilder>>privateNewSubclassOf:)

Sure. ClassBuilder wants to be independent+under+all+circumstances, that's  
why there are so many setters+getters for Behavior withAllSubclasses. I  
guess some of them (getters+setters) can be consolidated with Traits,  
thereby encapsulating behavior instead of just accessing behavioral state.

> Interesting...

:-)

/Klaus

> Alexandre




More information about the Squeak-dev mailing list