On Sun, 04 Feb 2007 02:16:09 -0800, Klaus D. Witzel <[EMAIL PROTECTED]> wrote:

You might want to compare:

class side>>new
        | instance |
        instance := self new.
        instance thisAndThat "extra code needed".
        ^ instance

instance side>>initialize
        "sent automatically by Behavior>>new"
        iVar1 := 'text'.
        iVar2 := 0

The latter is preferable over the former (less code, less maintenance). But often people put utility methods like #on:, #with: etc on the class side, for non-trivial initializations.

When you say "sent automatically by Behavior>>new" is that true? In other words:

x := abitraryObject new.

results in an attempt to call arbitraryObject>>initialize?

From the (re-)usability point of view, if you had getters/setters (like in traits), the perfect approach is
        x := MyClass new setY: 'text';
                setZ: 0;
                yourself.

Or, like I prefer to do it
        (x := MyClass new)
                setY: 'text';
                setZ: 0.

I suppose we don't worry much about the "waste" of, say, setting up some features with default values and then having to discard those when the user sets them to something actually useful?

        ===Blake===
_______________________________________________
Beginners mailing list
[email protected]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to