Using methods in the superclass' superclass 
Author Message
 Using methods in the superclass' superclass

I am porting some st80 code that was originally done by modifying Analyst
Spreadsheet classes rather than by subclassing them.  I am attempting to
remedy this situation by creating subclasses that override only the methods
that really need to be overridden.  One problem I am getting is that I have
to override methods that call methods in the superclass.  This is easy to do
by using the pseudo-variable "super".  The problem is that I end up calling
the method that exists in the immediate superclass (the one I just subclassed
from) rather than ITS superclass.  Maybe an example would suffice:

        Matrix variableSubclass: #SpreadsheetHolder
        SpreadsheetHolder variableSubclass: #MySpreadsheetHolder

When I override a method from SpreadsheetHolder in MySpreadsheetHolder, I would
like to access methods that really exist within Matrix.  If I use "super" I
get methods that are in SpreadsheetHolder.  My current work around is to
create methods in SpreadsheetHolder that do nothing but call the method in
"super" that I need to use in MySpreadsheetHolder.  My question is: Is this
the only way to do what I want?  Am I missing the boat somewhere?  Should I
try to restructure the class hierarchy so that there never is a case where
this needs to happen?

Direct E-mail is fine, unless this seems to be a topic that could use some
open discussion.

Julian J. Watkins

Mon, 01 Nov 1993 04:36:28 GMT  
 Using methods in the superclass' superclass
For example:

A superclass: Object

B superclass: A
    super initialize

C superclass: B
    A's initialize, but not B's

The program transformation I use in this case is to break A>>initialize
into submethods (i.e. initialize sends "self initializeFoo"), then
C>>initialize can send "self initializeFoo" instead of "super initialize".
In practice I find that this situation arises when I have one method doing
too many things, so the resulting code is cleaner and easier to


Tue, 02 Nov 1993 00:07:21 GMT  
 Using methods in the superclass' superclass

Watkins) writes:
> I am porting some st80 code that was originally done by modifying Analyst
> Spreadsheet classes rather than by subclassing them.

[...discussion of problem omitted...]

Class Object has a number of messages that are overridden, that you still
want to be able to get to directly.  "new" is a good example of this.  The
provision for allowing direct access to the functionality of new without
mucking about in the methods implemented in the intermediate ancestors was
to create a "basicNew" method that does the same thing.  So even though
"new" is overridden, you can still always get to "basicNew".

So if you have a message "spam" in Matrix, move the body of the method to
"basicSpam", and change "spam" to just do "^self basicSpam".  Then your
subclass can say "super basicSpam" anywhere it needs to bypass the code in

By the way, what *are* you doing that needs to get directly to methods in
Matrix?  I seem to remember the only behavior SpreadsheetHolder inherits
from Matrix is the various atXXX: and atXXX:put: accesing methods.  I guess
I should have made SpreadheetHolder be a subclass of Object with a Matrix
in an instance variable, and then you wouldn't have to muck about with
all this bypassing and disinheritance.  Sorry, but I had only been
programming in Smalltalk a few weeks when I started the design.  But next
time I'll know...

Joshua Susser, Object Percussionist
Apple Computer, Advanced Technology Group

Macintosh Jr. - The power to crush the other kids.

Wed, 10 Nov 1993 04:49:14 GMT  
 [ 3 post ] 

 Relevant Pages 

1. Invoking a subclass's method on its superclass's instance

2. calling superclass' method with list positional arg

3. Viewing methods from superclass(es)

4. Is it slower to call superclass methods ?

5. call to a superclass method

6. superclass method calling problem

7. Calling a (any) superclass method when already have one by that name

8. jython question: accessing protected superclass methods

9. Calling superclass method with variable args?

10. How to inherit a subset of methods from a superclass

11. Which class/superclass implements a method ?

12. Which class/superclass implements a method ?


Powered by phpBB® Forum Software