Question about initialize

Frank Shearar Frank.Shearar at rnid.org.uk
Tue Nov 23 11:06:48 UTC 2004


Joseph Frippiat <frippiat.j at kst.be> wrote:
> Hi,
> 
> What is the utility to have 2 initialize methods, one for the 
> class and one
> for the instance.  When are they called ?
> 
> Thanks
> 
> Joseph

The crucial thing to remember here is that a class is itself an instance(*). When you call

  f := Foo new.

you're sending #new to the _object_ called Foo (which happens to be a Class). Then Foo class>>new calls the instance-side #initialize.

Foo class>>initialize (the class-side initialise) will run when the _class_ is instantiated (as opposed to instantiating an instance of that class).

Both #initialize perform the same function, that of initialising a new instance. However, in the instance-side #initialize (i.e., Foo>>initialize) you initialise an instance of a class, and in the class-side (i.e., Foo class>>initialise) you initialise the object representing the class itself.

(*) I can't remember what type a class is - Class? Metaclass?

frank


*******************************************************************
This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom they are addressed. Any views or opinions expressed
are solely those of the author and do not necessarily represent
RNID policy.
If you are not the intended recipient you are advised that any
use, dissemination, forwarding, printing or copying of this
email is strictly prohibited.
If you have received this email in error please notify the RNID
Helpdesk by telephone on: +44 (0) 207 296 8282.
The Royal National Institute for Deaf People
Registered Office 19*23 Featherstone Street
London EC1Y 8SL No. 454169 (England)
Registered Charity No. 207720
********************************************************************




More information about the Squeak-dev mailing list