[squeak-dev] Self new in arrowPrototype

Ralph Johnson johnson at cs.uiuc.edu
Fri Jun 3 12:15:21 UTC 2011


I haven't decided whether your conclusion is right, but your first
point is wrong.  It would be wrong to call this method "new" because
it is not creating a new PolygonMorph, it is creating a factory for
PolygonMorph's, i.e. it is creating a new prototype.  "new" should
just copy the existing prototype.

I assume that PolygonMorph doesn't define "new".   If it did, would
you want this method to call it?  What would happen if you made a
subclass of PolygonMorph?  I bet that the purpose of using the
prototype pattern here is to avoid having to make subclasses of
PolygonMorph, and if you did, you wouldn't want to call arrowPrototype
on it anyway.  If that is true, it really doesn't matter whether you
use "self" or "super" here.

-Ralph Johnson

On Fri, Jun 3, 2011 at 1:21 AM, Rodney Polkinghorne
<rodneyp at physics.uq.edu.au> wrote:
> The arrowPrototype class method of PolygonMorph looks like this:
>
> arrowPrototype
>        "Answer an instance of the receiver that will serve as a prototypical arrow"
>
>        | aa |
>        aa := self new.
>        ... initialize aa ...
>        ^ aa
>
> I think the "self new" should be "super new", reasoning as follows:
>
> 1. It's purely a matter of taste whether the two polygon constructors
> are called "new" and "arrowPrototype", or
> "psychedelicTrianglePrototype" and "new".
> 2. A "new" method should not send "self new".
> 3. Therefore, no constructor should send "self new".  (In particular,
> self might belong to a subclass, whose "new" method invokes this very
> constructor.)
>
> Is the bug in the code, or my logic?
>
> Rodney
>
>



More information about the Squeak-dev mailing list