About KCP and automatic initialize

Torge Husfeldt torge.husfeldt at gmx.de
Wed Sep 10 07:38:38 UTC 2003


Hi Richard,
On Wed, 10 Sep 2003 16:51:58 +1200 (NZST), Richard A. O'Keefe 
<ok at cs.otago.ac.nz> wrote:

> Torge Husfeldt <torge.husfeldt at gmx.de> wrote:
> 	Here is the sUnit test that comes along with the above change,
> 	preventing anybody from accidentally implementing super new
> 	initialize again.
> 	
> I hope it doesn't prevent people *deliberately* doing it.
> - They might be trying to write code that will port to another Smalltalk.
> - They might be overriding a super that does something else.
First of all: It doesn't prevent people to do anything.
It is (you can read all sUnit tests that way) just a piece
of active documentation that is supposed to never get outdated
(ok there may be some work towards this point...).
Every time the developer runs the tests with more than
one 'super new initialize'(sni) method in the image, he will
be reminded (by a failing test with a good comment -hm,hm yet to write)
that it doesn't comply with the standard design.
If he insists to have his sni-method he has two choices:
1) Just leave it at that and have a test that fails
2) follow the instructions in the test comment to make the
sni method invisible to the test (say: put a self flag:#intentional in it).
>
> Object subclass: #Hairy
> class methods
> newFor: aNode
> ^self basicNew initializeFor: aNode
> new
> ^self newFor: self defaultNode
>
> Hairy subclass: #Legs
> methods
> initialize
> length := 2.
> class methods
> new
> ^super new initialize
>
> I think it's clear that super new initialize _should_ be allowed here.
>
>
HTH,
Torge


-- 
Der Mensch kann wohl tun, was er will, aber er kann nicht wollen, was er 
will.
(Schopenhauer)



More information about the Squeak-dev mailing list