[Newbies] Instance Creation Howto

stéphane ducasse ducasse at iam.unibe.ch
Sun Aug 13 21:36:53 UTC 2006


are you sure that your new2 method (initializer) is on the class side?
If this method should be sent to a class then it should be defined on  
the class side (click on the class button)

ComplexClass new2 is sent to the class ComplexClass itself so it  
should be defined on the class side
of the Complex class.

Stef

On 13 août 06, at 23:23, hypolit wrote:

> 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.
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list