Stupid Question?

Randal L. Schwartz merlyn at stonehenge.com
Wed Jan 16 17:52:31 UTC 2008


>>>>> "Richard" == Richard Eng <richard.eng at rogers.com> writes:

Richard> In #renderContentOn:, I write to the Transcript and get aValue, as
Richard> expected.  This is contrary to what you're telling me *if* the object
Richard> is created with #clientId = aValue *before* #initialize starts to
Richard> execute.

The purpose of aClass>>#initialize is to make a "bare object" with the
internal state set up so that it can be *any* instance of that class.

If you want a specific state set from a class-side constructor, then you do as
has been said a few times in this thread already: call a (often private)
instance method that further tweaks the state.

"Foo class" makeWidgetWithX: x andY: y "instance creation"
    ^self basicNew initialize
      setX: x setY y;
      yourself.

"Foo" setX: anXInteger andY: aYInteger "private"
    x := anXInteger. "set instance var"
    y := aYInteger. "set instance var"
    "returns self, but we don't care"

Then you call

     myFoo := Foo makeWidgetWithX: 123 andY: 45.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



More information about the Squeak-dev mailing list