[Seaside-dev] basicNew

Julian Fitzell jfitzell at gmail.com
Sun Oct 5 10:19:55 UTC 2008


On Sun, Oct 5, 2008 at 12:12 PM, Julian Fitzell <jfitzell at gmail.com> wrote:
> I've always done something like:
>
> WAPoint class>>x: xNumber y: yNumber
>  ^ self basicNew initializeWithX: xNumber y: yNumber; yourself
>
> WAPoint>>initializeWithX: xNumber y: yNumber
>  self initialize.
>  x := xNumber.
>  y := yNumber.
>
> If you really want #new to work and there are reasonable defaults, then add:
>
> WAPoint class>>new
>  ^ self x: 0 y: 0
>
> Is there a problem with this approach that I'm missing?

I should add that this assumes that your initialize methods are only
taking "required" parameters. In other words, if your object can
function without being initialized with a certain value it probably
should not be part of the initialization method. This way, you pretty
much always have one designated initializor per class that takes all
the required parameters for it and its superclasses. The instance
creation methods can call accessors to set any optional state.

I guess the disadvantage is that subclasses might have to override a
lot of instance creation methods but, if a subclass adds *new* and
*required* initialization state, that's sort of to be expected, no? If
you add new optional state, the old instance creation methods still
work.

Julian


More information about the seaside-dev mailing list