1

Assume object is an instance of class C. Also assume that object has an instance-specific method m attached to it. The method m is defined in both C and its superclass C0. The question is, which method should the expression

super m

invoke when self == object, and why?

I see two possible answers:

  1. C >> #m (the method in the object class)
  2. C0 >> #m (the method in the object class superclass)

EDIT

Even though the way we implement instance-specific behavior shouldn't matter for the semantics of super, let me point out that my favorite implementation is the one that places the so called MethodDictionaryArray (or MDA for short) in object headers, instead of the object class. As you can imagine, a MDA contains the method dictionaries of the inheritance chain.

With this implementation you can put instance behavior in a new MethodDictionary (MD) and redefine the object's MDA as the nested array #{MD. MDA}.

Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
  • Please clarify the inheritance chain. There are no actual "instance specific" methods in Smalltalk (at least not the ones I know) because behavior is always defined in a class. The way instance-specific methods work is that the object's class is changed to an anonymous subclass of its former class (we call that a "uniclass" in Squeak). – codefrau Aug 25 '15 at 17:23
  • @BertFreudenberg please notice the **EDIT** I've added. – Leandro Caniglia Aug 25 '15 at 23:50
  • Leandro, I take it you've already read through the answers to [this question](http://stackoverflow.com/q/14196417/983430)? – Amos M. Carpenter Aug 26 '15 at 00:25
  • @AmosM.Carpenter yes, I had read it a while ago. Do you think there is some hint there that would help with my question here? – Leandro Caniglia Aug 26 '15 at 00:43
  • @LeandroCaniglia Yeah, I think several of the links in the accepted answer might be helpful. I'm not too familiar with changing methods just on specific instances, so I can't offer an answer myself. But Hernan's answer to that question, even though more for VW, should help you get a test case set up to answer your own question. – Amos M. Carpenter Aug 26 '15 at 00:49

3 Answers3

4

IMHO it should invoke C0>>m to behave just like 'normal' instances of C. The implementation detail of how the instance-specific behavior is realized shouldn't matter. If you copy a method from C to its instance, it should ideally behave exactly the same as before.

codefrau
  • 4,583
  • 17
  • 17
1

The standard definition of super is that super sends a message to the same receiver as self but starts the method lookup in the class above the one where the current method is defined.

David Buck
  • 2,847
  • 15
  • 16
  • Right. But here the whole point is that the definition is not that easy to apply because the instance-specific method is not defined in any class. – Leandro Caniglia Aug 29 '15 at 01:06
  • I get it now. I would then think of it as follows: The normal search path for methods is a linear list. With instance-specific behavior, a new method dictionary is added to the start of the list. I would think, then, that super means to start searching in the next method dictionary in the list which would be for the class C. – David Buck Sep 01 '15 at 01:12
  • Exactly. And you would also arrive at the same conclusion if you implement the specific behavior in a "lightweight" instance-specific class because such a class would be a subclass of the original one. But then, we would be deciding the semantics from the implementation and that's what I'm questioning. – Leandro Caniglia Sep 02 '15 at 01:47
0

It seems to me that one can phrase the definition a bit differently,
to get at the proper resolution of the semantics.

If we consider the normal case to be equivalent to

'do not include in the search any methods that are defined
 by the receiver, include only those which are inherited'

then the implementation details are not required
when we are deciding which answer to expect.

Jim Sawyer
  • 113
  • 4