[squeak-dev] Re: Self new in arrowPrototype

Rodney Polkinghorne rodneyp at physics.uq.edu.au
Tue Jun 7 00:31:50 UTC 2011


Ralph Johnson, replying to me:

> "new" should just copy the existing prototype.

Thanks.  That makes general sense, but I'm still confused about some
details.  Suppose I want to define IndicatorMorph, an arrow-like
subclass of PolygonMorph that will be attached to a DialMorph.

1. Presumably, IndicatorMorph class>>initialize constructs a prototype
by sending arrowPrototype to PolygonMorph class.  Where should this be
stored?

2. IndicatorMorph>>new copies the prototype, giving another
PolygonMorph.  Then a miracle occurs.  Finally, the new method has an
IndicatorMorph, which it answers.  How do mortal programers reproduce
the miracle?

If this is covered in Objects for Dummies, please tell me where to find a copy.

> I assume that PolygonMorph doesn't define "new".   If it did, would
> you want this method to call it?

PolygonMorph does define new - it answers a brightly coloured
triangle.  The arrowPrototype method is just like new, except it has
arrows: #forward instead of arrows: #none, and a few things like that.

> What would happen if you made a subclass of PolygonMorph?

When I tried it, its new method went into an infinite chain of
messages, and I emailed the list.

> I bet that the purpose of using the
> prototype pattern here is to avoid having to make subclasses of
> PolygonMorph

In that case, how should IndicatorMorph work?  I can duplicate
PolygonMorph>>arrowPrototype and call it IndicatorMorph>>new, but that
seems wrong for all kinds of reasons.

Thanks for your help.

Rodney



More information about the Squeak-dev mailing list