Re: The Override Problem



Tom N wrote:
> Roedy Green wrote:
>
>> I am about the describe one of the most frustrating features of Java
>> -- the total lack of safety nets when it comes to overriding methods.
>> Tracking these down take me days.
>>
>> Any hints on techniques for ensuring the error never happens are
>> welcome or for finding them when suspected.
>>
>> I love abstract methods. The compiler dutifully checked that I
>> remembered to implement every last one, to spell it perfectly and to
>> get the signature bang on.
>>
>> But sometimes I want to provide a default implementation that I
>> occasionally override.
>>
>> I tend to screw up and make a teensy spelling error in the name, or
>> get the method signature off by a hair. The compiler gives me no
>> warning at all. Basically my new methods is totally ignored and that
>> class uses the default implementation.
>
> JBuilder provides an "override method" wizard which can insert stubs
> for all inherited abstract methods and can insert stubs for selected
> inherited concrete methods. There is also a wizard to implement an
> interface.

I was going to say the same: use a decent IDE.

> Presumably some other tools will do something similar.

Yes, eclipse has similar tools: you can select the methods you want to
override and get appropriate stubs.

> That solves the problem when initially writing the subclass but it
> doesn't handle the case where you either later change the signature
> of the parent class abstract method or accidentally change the
> subclass by editing.

No problem with eclipse if you use the refactoring "rename": all methods
in sub classes are changed similarly.

Kind regards

robert

.



Relevant Pages

  • Re: The Override Problem
    ... > -- the total lack of safety nets when it comes to overriding methods. ... > get the method signature off by a hair. ... JBuilder provides an "override method" wizard which can insert stubs for all inherited abstract methods and can ... change the signature of the parent class abstract method or accidentally change the subclass by editing. ...
    (comp.lang.java.programmer)
  • Re: feature question
    ... a base method BM with signature "C M;" ... an override OM with signature "D M;" ... DerivedFactory GetFactoryin the DerivedObject class ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A text from a book which must be wrong(virtual, abstract metod)
    ... abstract accessor) in a derived class.Any classes derived from this abstract ... class must override these abstract methods and provide new implamantations ... What override a virtual method with an abstract method ?? ... public abstract class Derived: Base ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: method overriding
    ... Parent Parent.method ... Nothing like that is possible for Java, in fact, I haven't ... would override Parent.method if all slots in the child method's signature ...
    (comp.lang.java.programmer)
  • Re: override by name in c#?
    ... > public int Add ... That's not an override - it doesn't have the override modifier. ... That seems odd if you've changed the signature - it shouldn't. ... > because it's not the same signature, it does, and apart from the warning, this ...
    (microsoft.public.dotnet.languages.csharp)