Should certain abstract classes be instantiable?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 3 12:57:46 PDT 2009


Ary Borenszweig wrote:
> Andrei Alexandrescu wrote:
>> Jarrett Billingsley wrote:
>>> On Thu, Oct 1, 2009 at 11:48 PM, Andrei Alexandrescu
>>> <SeeWebsiteForEmail at erdani.org> wrote:
>>>>> But.. you mark something abstract when you want it to be .. abstract.
>>>>> How would you argue that abstract is basically a no-op when used on
>>>>> methods with bodies?
>>>> It's not a no-op. Try it.
>>>
>>> Yeah, not *currently*, but isn't that what you're proposing?
>>
>> No. I think it would help going back to my original message instead of 
>> asking one-liner questions. This would work much better in real life, 
>> but it's a time sink in a newsgroup. You spend five seconds on asking 
>> a question with a foregone answer just because you don't want to 
>> invest fifteen seconds in re-reading my initial post, and then you 
>> have me spend five minutes explain things again. It's counter-productive.
>>
>> If a class defines an abstract method and also provides a body for it, 
>> it still requires the derived class to override the method. So 
>> abstract still has some meaning.
> 
> Umm... so it defines a body that will never be used because that class 
> can't be instantiated and the method must be redefined by subclasses? 
> Isn't that the same as "doesn't provide a body"?

import std.stdio;

class A {
     abstract void fun() { writeln("wyda"); }
}


class B : A {
     void fun() { A.fun(); }
}

unittest {
     A a = new B;
     a.fun();
     a.A.fun();
}



Andrei



More information about the Digitalmars-d mailing list