[Seaside-dev] basicNew
Randal L. Schwartz
merlyn at stonehenge.com
Mon Sep 29 14:47:45 UTC 2008
>>>>> "Julian" == Julian Fitzell <jfitzell at gmail.com> writes:
Julian> Seaside-Core-pmm.267.mcz
Julian> - use #new instead of #basicNew for WACallbackRegistry, using
Julian> #basicNew has already lead to interesing bugs in other places
Julian> I always thought the pattern was:
Julian> Foo class>>bar: param
Julian> ^ self basicNew initializeWithBar: param
Foo> initializeWithBar: param
Julian> self initialize.
Julian> bar := param
Julian> I guess calling new instead of basicNew and not call #initialize from
Julian> #initializeWithBar: also works, but means you don't have control over
Julian> when (or if) #initialize gets called. I have to admit that the whole
Julian> initialization pattern feels a bit ugly both ways though. Is this the
Julian> preferred pattern throughout now?
The Squeak way has been to have something equivalent to:
Class class >> new
^self basicNew initialize.
Class >> initialize
^self.
So for specialization in initialization, you add:
MyClass >> initialize
super initialize.
[stuff here].
^self.
As in, it's important for initialize to always call super, and also to always
return self, and return a sane object that might only need some additional
settings.
And for specialized constructors, you add:
MyClass class >> on: anObject
^self new on: anObject; yourself.
MyClass >> on: anObject
[stuff here].
This is the Squeak pattern as I understand it, and since Seaside is sourced in
Squeak, this is the pattern that has been established for specialization in
Seaside items.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
More information about the seaside-dev
mailing list