About KCP and automatic initialize

Richard A. O'Keefe ok at cs.otago.ac.nz
Sun Sep 14 22:57:33 UTC 2003


Avi Bryant <avi at beta4.com> wrote helpfully about the initialisation/
creation conventions for FoundationKit for Objective C.

>>>>>	- The designated initializer must call its superclass' designated  
	initializer.
	...

	So, the short answer to Julian's question is: yes, use #basicNew in  
	#forClass:.  If you make sure to follow the rest of these conventions,  
	the problems that people have with #basicNew (in terms of missing  
	superclass initialization) should not come up.
	
There is an implicit assumption here, which is that superclass
initialisation is always (but ALWAYS) appropriate for subclasses.

This is very often true.  One might even say that it is usually true.
But in a language like Smalltalk, where the superclass initialisation
method may call instance methods that are overridden by the subclass,
it is certainly not a *safe* assumption.

People often think of initialising an object in terms of initialising
its instance variables.  That's a large part of it, but some of the
information about an object may be held outside it (an insight going
back at least to the Bobrow & someone CACM paper which spelled out the
idea of putting some object properties in separate hash tables).  For
example, initialisation might involve registering a finaliser.

I don't want to be misunderstood as claiming that you _often_ want to
bypass an inherited initialisation method, only that it is _sometimes_
legitimate to do so, and if you are forbidden to do this by your language
or library, then you have to drive a wedge between what the _language_
called "initialization" and the _real_ initialisation, which means that
there's an interval when an object is accessible and "initialized"
but not _really_ initialised.  And that's not usually desirable.



More information about the Squeak-dev mailing list