[Newbie] Morph class>>new

Christian Hofer Christian.Hofer at gmx.de
Mon Apr 14 12:48:32 UTC 2003

Thank you for your answers!

>You should implement
>MyMorph class >>withTitle: aString
>	^ self new title: aString
>If your #initialize method depends on title already having a value. 
>Move that dependent code into #title:.

I suppose this is not a must but a useful convention?
Or would it crash my system if I would change:
Morph class>>new
^self basicNew initialize
(I haven't dared yet.) I mean, this is simply what I have read in Kent
Beck's Best Practice Patterns (IIRC), that 'super new initialize' has the
disadvantage that it forbids me to override this method in a subclass, if I do not
want "initialize" to be called more than once. (But as I found out Squeak seems
to be quite concerned of your personal sanity if you want to change the
new-method anyway.)

>Object is not, but Object class is a subclass of Behavior.  When sending
>a message directly to a class, ie. Object new, you are looking up
>methods in its class, ie. Object class, which has a separate but similar
>class hierarchy to Object.  Highlight the class button for any class in
>the browser and choose 'show hierarchy' from the class pane menu. 

Ok. But why can't I see it with 'browse hierarchy' the same way (that's what
I did)?

>> BTW: I often forget to call "super initialize" in my
>> MyMorph class>>initialize
>> methods. This sometimes leads to Squeak crashing completely (not even 
>> alt-. does help) when I open MyMorph in World. Could there be something 
>> done about it?
>Always call super in your initialize method.  This should not be hard to
>remember since the initialize protocol is not something you create

Should not, but for me, obviously, it is... I know that the openness of
Squeak makes it inevitable that a developer can easily crash the environment. But
that this is possible by simply forgetting a 'super initialize' in a method
is not very developer-friendly. I was just hoping somebody knows a fix to
prevent this.


+++ GMX - Mail, Messaging & more  http://www.gmx.net +++
Bitte lächeln! Fotogalerie online mit GMX ohne eigene Homepage!

More information about the Squeak-dev mailing list