Re: The Override Problem



Thomas G. Marshall wrote:
Raymond DeCampo coughed up:

Tim Tyler wrote:

Raymond DeCampo <nospam@xxxxxxxxxxxx> wrote or quoted:


Tim Tyler wrote:


Andrea Desole <news@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote or
quoted:


yes, but the discussion is more about the case when you make a
mistake and you don't override a method that you should actually
override.

Some way of indicating methods that *must* be overriden in subclasses may be an idea with some virtues.

That's what the abstract keyword does.[...]


...except that it doesn't work under some circumstances - thus my:
"unless you really need a base class implementation [...]" comment.

I afraid you've lost me here. What use is the base class implementation if your intent is that every subclass override the method? If you intend to have every subclass invoke super.method1(), then it would be better to have method1() be abstract in the superclass and ask every subclass to invoke super.method2(), where method2() is protected. Or actually, what would be better, would be to make method1() final in the base class, have it invoke method2() and make method2() abstract and protected.

So I don't really see the case you are addressing here.


I see that.  You're missing the following notion I think:

Given two classes, in this relationship:

    A <|-- B

Given the method

    A.method()

It is not amazingly uncommon to see a situation where the designer wants an implemented A.method() because the A class must be instantiatable, but for all subclasses to require that the subclass override it with one of their own. If the method were declared.

    public abstract void method() {...}

Then there would never be any way to instantiate an A by itself. You can make arguments as to whether or not this is something "good" to do in OO, but I believe that it would be a "fine" thing to do if you had a keyword enforcing it:

    public must_override void method() {....}

But I'm not prepared to go to war over the notion. I've seen things be declared non-abstract for this very reason alone.



It strikes me that the "proper" way to do this would be to have an abstract class and supply a particular implementation.


In this sense, "proper" means that this accomplishes the programming semantics you desired using means supplied inherently by Java, without depending on external programming contracts.

Thank you for the exposition.

Ray

--
XML is the programmer's duct tape.
.



Relevant Pages

  • Re: What can I store in LPARAM
    ... I'm not saying you're wrong, but with my call back up to the base class, ... may choose to override it completely, or by adding code before or after ... comments below regarding leaf. ... This means that a subclass can't change the method body behind ...
    (microsoft.public.vc.mfc)
  • Re: virtual and override methods
    ... If C didn't have an override, ... > inherits the virtual method from A? ... > make calls to overridden members in the base class by prefacing the ... > the other subclass uses this ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Newbie: Can a static method be overriden?
    ... a subclass cannot override a class ... > static String aMethod() ... > In this code a static method aMethod from class Mammals is overriden ...
    (comp.lang.java.programmer)
  • Re: Newbie: Can a static method be overriden?
    ... a subclass cannot override a class ... > static String aMethod() ... > In this code a static method aMethod from class Mammals is overriden ...
    (comp.lang.java.help)
  • virtual and override methods
    ... I have a question about virtual and override methods. ... Class A contains a virtual method, and B contains an override method. ... In other words, if base class A contained public virtual int Method, ... the other subclass uses this ...
    (microsoft.public.dotnet.languages.csharp)