[Newbies] Multiple constructors

Todd Blanchard tblanchard at mac.com
Thu May 11 17:40:25 UTC 2006


Any class method can be a constructor.  

At the end of the day (bottom of the stack) most new instances are created with basicNew.  This is a low level call that just allocates the object's memory and associates it with the class (and sets all ivars to nil).  The default ctor in user space is new, which calls basicNew and then initialize on the object.

Suppose you have a Socket class and want a constructor that takes an ip address.  You'd just create a class side method

openOnIpAddress: anAddress
   ^self new openOn: anAddress.

or something like that (this is totally off the top of my head - any resemblance to actual Squeak code is purely coincidental). 

-Todd Blanchard

On Thursday, May 11, 2006, at 10:05AM, Rich <rjseagraves at gmail.com> wrote:

>I watched Stephane's Squeak videos (they helped alot btw) and was left
>wondering how one goes about making multiple constructors for a class.
> Is it even possible?  Thank you.
>
>-Rich
>_______________________________________________
>Beginners mailing list
>Beginners at lists.squeakfoundation.org
>http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>


More information about the Beginners mailing list