Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!howland.reston.ans.net!math.ohio-state.edu!news.cyberstore.ca!vanbc.wimsey.com!fonorola!news!dbuck
From: dbuck@infoweb.magi.com (David Buck)
Subject: Re: #basicNew
Sender: news@magi.com
Message-ID: <DAuyIs.4y6@magi.com>
Date: Wed, 28 Jun 1995 00:54:28 GMT
References: <3saqtd$phm@wraith.cc.uow.edu.au>
Nntp-Posting-Host: infoweb.magi.com
Organization: Magi Data Consulting
Keywords: new @basicNew
Lines: 43

In article <3saqtd$phm@wraith.cc.uow.edu.au>,
Harendra Mariappa <hari@wraith.cc.uow.edu.au> wrote:
>
>Hi
> when should one use self new & super new also when should we use new
>and when to use basicNew.
>Thanking in advance
>hari
>hari@cs.uow.edu.au

Use 'self new' is you are writing a class method called something other 
than new which needs to create an instance.  Use super new if you are 
writing a method called new which needs to create an instance and 
initialize it in some way.  The super means "send a message to self but 
start looking for the method in the class above the one where the current 
method is defined."

Use basicNew when you want to create an instance without doing any of the 
initialization that new does.  By default, new and basicNew do the same 
thing.  The trick is that subclasses often re-implement new to do 
initialization.  You should never re-implement basicNew so it always 
creates an uninitialized instance.

Examples:

!MyClass class methodsFor: 'instance creation' !
makeSpecialInstance
   ^self new data: 'your name'; yourself!

new
   ^super new initialize! !

!MySubClass class methodsFor: 'instance creation'!
createRawInstance
   ^self basicNew! !


David Buck
dbuck@magi.com
The Object People



