sharp@ksi.cpsc.ucalgary.ca (Maurice Sharp) (11/24/89)
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 2500 University Drive N.W. sharp@ksi.cpsc.UCalgary.CA Calgary, Alberta, T2N 1N4 ...!alberta!calgary!sharp
johnson@p.cs.uiuc.edu (11/26/89)
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
riks@csl.sony.co.jp (Rik Smoody) (11/29/89)
In article <2160@cs-spool.calgary.UUCP> sharp@ksi.cpsc.ucalgary.ca (Maurice Sharp) writes: > 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
andrew@computing-maths.cardiff.ac.uk (Andrew Jones) (11/30/89)
In article <2160@cs-spool.calgary.UUCP> sharp@ksi.cpsc.ucalgary.ca (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 ... > >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: >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
bwk@mbunix.mitre.org (Kort) (12/04/89)
In article <2160@cs-spool.calgary.UUCP> sharp@ksi.cpsc.ucalgary.ca (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
dans@bcsaic.UUCP (Dan Small) (12/06/89)
In article <81699@linus.UUCP> bwk@mbunix.mitre.org (Barry Kort) writes: > >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