Re: The Override Problem
- From: Raymond DeCampo <nospam@xxxxxxxxxxxx>
- Date: Wed, 13 Jul 2005 01:31:40 GMT
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. .
- References:
- The Override Problem
- From: Roedy Green
- Re: The Override Problem
- From: Paul Bilnoski
- Re: The Override Problem
- From: Andrea Desole
- Re: The Override Problem
- From: Paul Bilnoski
- Re: The Override Problem
- From: Andrea Desole
- Re: The Override Problem
- From: Tim Tyler
- Re: The Override Problem
- From: Andrea Desole
- Re: The Override Problem
- From: Tim Tyler
- Re: The Override Problem
- From: Raymond DeCampo
- Re: The Override Problem
- From: Tim Tyler
- Re: The Override Problem
- From: Raymond DeCampo
- The Override Problem
- Prev by Date: Re: Reading Emails
- Next by Date: Re: get property of a class
- Previous by thread: Re: The Override Problem
- Next by thread: Re: The Override Problem
- Index(es):
Relevant Pages
|