Stupid Question?

Laurence Rozier laurence.rozier at
Wed Jan 16 18:43:01 UTC 2008

Though many of the comments have touched on the key points, you might find
it useful to look at Kent Beck's Smalltalk Best Practice Patterns book which
really covers this and other topics well. It's definitely not a stupid
question and one has to think about the downstream implications of choosing
an approach particularly wrt subclasses. Because of that I tend to use a
variation of the initializeWith: approach that  looks something like:

materializeUsing: aDictionary

    self beforeMaterializing: aDictionary.
    self initializeUsing: aDictionary.
    self afterMaterializing: aDictionary

In Object, beforeMaterializing: and afterMaterializing: do nothing and
initializeUsing: simply calls initialize. Having before and after hooks
makes it easier to evolve the class. You can use this approach with many
existing classes, though you may have to be careful to understand how a
class's initialize really works.

Then on there are two class side methods,

materializeUsing: aDictionary
^self basicNew materializeUsing: aDictionary

^self materializeUsing: Dictionary new.

The actual code in my framework is slightly more complicated but not by
much. There is some overhead but for me it's a small price to pay for the
consistency and flexibility it buys.



On Jan 16, 2008 8:46 AM, Richard Eng <richard.eng at> wrote:

> I have a stupid question:  How do you pass information into the
> #initialize
> method at object creation time? You can't use any of the instance methods
> or
> accessors because they don't yet exist! So how do you pass information in?
> Thanks,
> Richard
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Squeak-dev mailing list