Re: inheritance bug?

Daniel Bonniot <[email protected]> Wed, 25 Feb 2004 10:16:55 +0100
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
>>The problem is described in the C# article you linked to. If you
>>later introduce a method with the same name in an imported package,
>>you will suddenly override it silently, while you had no knowledge
>>of that method when you wrote your implementation. So there is
>>absolutely no guarantee that your implementation is meaningful for
>>that method, that it fullfills its contract, ...
>>    
>>
>
>And when we would like move some method definitions to an interface
>from class X, what can we do?
>
>We have to define a method in the interface with a different name
>"iMethodA", and provide an implementation of "iMethodA" for class X
>which forwards to the method we really would like to use:
>   iMethodA(X x) = x.methodA();
>  
>
Why would you need to do that?

If I understand correctly, the situation is:

  class A {}
  void methodX(A) { ... }

and you now want:

  interface I {}
  class A implement I {}
  void methodX(I);
  methodX(A a) { ... }

Well, you can simply do that. With a refactoring tool, this can be 
automated.

The point is that here you have the knowledge of the package that 
defines methodX (otherwise you would not even know it exists). So you 
have the opportunity to do the above refactoring.

The difference with the case I was presenting is that there you are 
modifying a base package, and that might create new behaviour in a 
client package _that you have never heard of_. Therefore, even the 
refactoring tool will not be able to detect the situation.

>>One more, huge advantage, is that when you read the code, you 
>>immediately see it's a overriding. You get more information, more 
>>context to understand the code.
>>    
>>
>
>Not really, the context to understand the code in overridden methods
>comes from seeing what the other implementations are. Any sane OO IDE
>provides quick access to senders and implementors - don't LISP IDEs
>bring together generic function implementations?
>  
>
Right, a good IDE greatly helps. In a way, an IDE provides a kind of 
alternative, visual syntax for the language, so the decisions about the 
raw syntax have less importance in that case. The above problem remains, 
though.

By the way, we need contributors to the Eclipse plugin! :-)

Daniel



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click