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
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@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:
- 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
"Rodney" == Rodney Polkinghorne rodneyp@physics.uq.edu.au writes:
Rodney> I think the "self new" should be "super new", reasoning as Rodney> follows:
Lemme stop you right there (since you aren't in the #new method):
A simple rule of thumb is that you NEVER call "super XXX" from any method other than "XXX". Violate that, and you have code smell.
The point of super is to get at my superclass definition of the method I'm currently in. Not to go messing with the protocols in general.
squeak-dev@lists.squeakfoundation.org