Basic smalltalk browser question: class variables initialization
Alejandro F. Reimondo
aleReimondo at sugarweb.com
Sun Dec 19 14:03:29 UTC 1999
Hi Piero,
If you can defer class variable initialization to the time you will use it,
it is recomended to use a deffered initialization mechanism.
Consider this kind of initialization:
Object subclass: #Elephant
instanceVariableNames: ' head body tale '
classVariableNames: ' Dumbo '
poolDictionaries: ''
category: 'My Category'!
!MyClass class methodsFor: 'accessing' stamp: 'ale 15/12/1999 09:23'!
dumbo
"Returns Dumbo (the singleton elephant)."
Dumbo isNil ifTrue: [ self initializeDumbo ].
^Dumbo! !
!MyClass class methodsFor: 'initialization' stamp: 'ale 15/12/1999 09:24'!
initializeDumbo
" Private - Initialize Dumbo."
Dumbo := self new actAsDumbo;yourself ! !
Using deffered initialization and accessors for global variables
you does not need to initialize the hole class...
Consider that can can be a situation that you must initialize
states only at proper time... only in this situations
I consider interesting to use an explisit initialization.
Hope this can help to does not depend on #initialize messages
at end of a fileIn. (if all the source code has not filedin;
the class cant be used...
And if fileIn is aborted the class will not work properly)
cheers,
Ale.
----------
De: Piero Campanelli[SMTP:campanelli at skylink.it]
Responder a: campanelli at skylink.it
Enviado el: Domingo 19 de Diciembre de 1999 07:27
Para: squeak at cs.uiuc.edu
Asunto: Basic smalltalk browser question: class variables initialization
Hi.
I have a problem with class variables initialization. I made some classes
with class variables that need to be initialized first time. So after class
creation i do a:
MyClassName initialize
and all works !
But what happens when i 'File Out' my sources for another running image ?
When you do a 'File In' in a new image you have to remember to do a
"MyClassName initialize". Probably there is another method ......isn't there
?
Bye
More information about the Squeak-dev
mailing list
|