[Newbies] Instance Creation Howto
hypolit
hypolit at googlemail.com
Sun Aug 13 21:23:43 UTC 2006
Hello,
I am new to Smalltalk and Squeak in general. After having started to read
"Inside Smalltalk" and "Smalltalk by Example" i came along two similar
examples, which sound quite reasonable but don't seem to work in Squeak.
I want to create an instance of my own class "ComplexClass".
It is defined like this:
Object subclass: #ComplexClass
instanceVariableNames: 'firstVar secondVar'
classVariableNames: ''
poolDictionaries: ''
category: 'TestClass'
I can create instances with
aComplex := ComplexClass new.
normally.
But what if i wanted to call another method instead of "new" to create an
instance?
Take, for example, my method "initializer":
initializer
| aVariable |
aVariable := ComplexClass new.
aVariable firstVariable: 22.
aVariable secondVariable: 23.
^aVariable
In both books there are methods quite similar to my "initializer" method.
But if execute:
aComplex2 := ComplexClass initializer.
I get an error message, something like "Undefined Object does not understand
#initializer".
Do i have to write:
aComplex2 := ComplexClass new.
aComplex2 := aComplex2 initalizer.
That would work but it is quite ugly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20060813/4679d751/attachment-0001.htm
More information about the Beginners
mailing list