super super ? 
Author Message
 super super ?

     Does anyone know the solution to the following problem.  Assume
that there are 3 classes each of which implements a message called
foo.  Call the classes Class1, Class2 and Class3, where each is a
subclass of the other, i.e. :

   Object
      Class1
         Class2
           Class3

     The message 'foo' is defined in all three classes.  Let us say
that Class1 defines it as follows ;

        foo
          Transcript cr; show: 'Class1'; cr

     Class2 defines foo as :

        foo
          Transcript cr; show: 'Class2'; cr.
          super foo

THE PROBLEM :

     I want Class3 to call the foo of Class1 NOT Class2.  Is there a
way to do this ?

        Thanx in Advance
           eciruam
Maurice Sharp
University of Calgary Computer Science Department

Calgary, Alberta, T2N 1N4                          ...!alberta!calgary!sharp



Mon, 19 Apr 1993 01:56:00 GMT  
 super super ?

Strictly speaking, if Class2 overrides a method defined in its superclass,
Class1, then there is no way that its subclass, Class3, can access the
definition in Class1.  However, this is not a big problem in practice.

For example, Object defines at:, and Set undefines it by providing a
definition that generates an error if executed.  However, Dictionary,
a subclass of Set, needs to access at:.  The standard trick is for
Object to define a basicAt: that is the same thing as at:, and for
no class to redefine basicAt:.  This ensures that any class that
needs to access the basic at: definition will be able to.

Ralph Johnson



Mon, 19 Apr 1993 17:38:00 GMT  
 super super ?
Quote:

>     I want Class3 to call the foo of Class1 NOT Class2.  Is there a
>way to do this ?

self Class1.foo

That machanism should work at least whereever inheritance is properly
implemented (not that perverse, single-inheritance stuff)
Rik Fischer Smoody
Sony Computer Science Lab, Inc.,  3-14-13 Higashigotanda
Shinagawa-ku, Tokyo 141 Japan
(03)448-4380



Mon, 19 Apr 1993 04:38:00 GMT  
 super super ?

Quote:

>     Does anyone know the solution to the following problem.  Assume
>that there are 3 classes each of which implements a message called
>foo.  Call the classes Class1, Class2 and Class3, where each is a
>subclass of the other ...

>The message 'foo' is defined in all three classes ... THE PROBLEM:

>     I want Class3 to call the foo of Class1 NOT Class2.  Is there a
>way to do this ?

Ralph Johnson states:

Quote:
>Strictly speaking, if Class2 overrides a method defined in its superclass,
>Class1, then there is no way that its subclass, Class3, can access the
>definition in Class1.  However, this is not a big problem in practice.

And provides the standard work-around using the example of basicAt: and at:
for collections. This is the way I have always circumvented the problem.

However, if you have a Smalltalk-80 system containing the extension for
multiple inheritance (you will find the class MetaclassForMultipleInheritance
in category Kernel-Classes) then you might like to try defining the
following method in Class3:

foo
     ^self Class1.foo

The compiler will complain that Class1.foo is a new message. Tell it to
proceed at this point. This method will then kind-of use the method of
Class1 for foo.

The problem is, multiple inheritance in Smalltalk-80 is not bug-free,
so you might suddenly find that things go wrong! One certain problem
is that if Class1>>foo sends a message to super, then Class3>>foo will
send the message to Class2, NOT Object.

So if you're braver than I am, you're welcome to try it! Hope this helps.

Andrew Jones,
University of Wales College of Cardiff
Department of Computing Maths.
Maths. Institute
Senghennydd Road
Cardiff CF2 4AG
UK



Mon, 19 Apr 1993 13:34:00 GMT  
 super super ?

Quote:
(Maurice Sharp) writes:

 >      Does anyone know the solution to the following problem.  Assume
 > that there are 3 classes each of which implements a message called
 > foo.  Call the classes Class1, Class2 and Class3, where each is a
 > subclass of the other, i.e. :

 >    Object
 >       Class1
 >          Class2
 >            Class3

 >      The message 'foo' is defined in all three classes.  Let us say
 > that Class1 defines it as follows ;

 >   foo
 >     Transcript cr; show: 'Class1'; cr

 >      Class2 defines foo as :

 >   foo
 >     Transcript cr; show: 'Class2'; cr.
 >     super foo

 > THE PROBLEM :

 >      I want Class3 to call the foo of Class1 NOT Class2.  Is there a
 > way to do this ?

Write a class method for Class1 called foo as follows:

        foo
                self new foo.

Then call "Class1 foo" directly.  Simple, no?

--Barry Kort



Wed, 19 May 1993 20:45:00 GMT  
 super super ?

Quote:

>Write a class method for Class1 called foo as follows:

>    foo
>            self new foo.

>Then call "Class1 foo" directly.  Simple, no?

>--Barry Kort

I must disagree that this approach satisfies the original poster's problem.
The original requirement, as I interpreted it, was for an instance of Class3
to implement the instance method 'foo' as defined in Class1.  The approach
presented above causes a new instance of Class1 to implement the 'foo' method.
There is a BIG difference.  Specifically, if 'foo' requires access to the
values of instance variables in the instance of Class3, then the above is
useless.  The context in which 'foo' is intended to be executed is lost when
you execute it in the scope of the new instance of Class1, rather than the
original instance of Class3.

Dan Small, Boeing Computer Services



Wed, 19 May 1993 00:19:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Super Tagging and Super Invoice

2. super merryChristmas; yourself

3. DummyQuestion: #super

4. Pseudovariable super

5. super

6. Mouse Driver(DOS) for Super VGA

7. SUPER-PC

8. IMS Super Techie Question

9. Assembler super techie question

10. Super-techie question

11. SUPER HOMEPAGE BY VDV-SOFTWARE

12. "super" question for language experts

 

 
Powered by phpBB® Forum Software