Restricting super calls to inherited method

Andrew P. Black black at cse.ogi.edu
Sat May 19 22:18:22 UTC 2001


At 17:49 -0400 2001.05.19, Paul Fernhout wrote:
>"Andrew P. Black" wrote:
>>
>>  One more thought, inspired by the code examples.
>>
>>  It is ALWAYS possible to avoid super calls ENTIRELY.   The example 
>>that sends
>>
>>          self basicNew
>>
>>  rather than
>>
>>          super new
>>
>>  illustrates the technique.  If you would like to call super foo, just
>>  add a new method to the superclass,  say basicFoo, with body "self
>>  foo".   Then the subclass can call self basicFoo.
>
>Thanks for the idea!
>

The idea was OK but the details were broken.  What I wrote before 
does not, of course, work when the subclass overrides foo, which we 
must assume that it does,that being the reason that we want to call 
"super foo"!

What you actually have to do is go to the superclass and copy the 
body of foo into basicFoo.  Then redefine foo as "self basicFoo". 
Then the trick works.  Of course, you have to generate a new version 
of the name "basicFoo" each time that you do this in an inheritance 
chain.  This is exactly what is going on whith basicNew and new.

	Andrew





More information about the Squeak-dev mailing list