Squeak noob question - initialize
Stephan Rudlof
sr at evolgo.de
Tue Jun 29 01:55:01 UTC 2004
Steve,
Steve Greenberg wrote:
> ...
> Here is the source code. Can anybody tell me what I'm doing wrong?
>
> -------
>
> Object subclass: #ClassA
> instanceVariableNames: 'anIntA '
> classVariableNames: ''
> poolDictionaries: ''
> category: 'SEG'
>
> initialize
> anIntA _ 1.
>
> new
> ^ super new initialize
>
> -------
>
> ClassA subclass: #ClassB
> instanceVariableNames: 'anIntB '
> classVariableNames: ''
> poolDictionaries: ''
> category: 'SEG'
>
> initialize
> anIntB _ 1
You have to change this method to
initialize
super initialize.
anIntB _ 1
This is the way to call an overridden method in a superclass (and should
mostly be done this way in >>initialize methods).
>
> new
> ^ super new initialize
>
>
Note: this class method calls the overridden >>new in the superclass
ClassA, and the overriden >>new class method in the superclass ClassA
calls the >>initialize instance method in ClassB (not the one in
ClassA!). And the last one should call its overridden super >>initialize
in ClassA.
Greetings
Stephan
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|