Should certain abstract classes be instantiable?

Ary Borenszweig ary at esperanto.org.ar
Mon Oct 5 01:34:04 PDT 2009


Nick Sabalausky wrote:
> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
> news:ha8beq$2tn9$1 at digitalmars.com...
>> Ary Borenszweig wrote:
>>> 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();
>> }
>>
> 
> Not a rhetorical or a loaded question: Has that sort of thing ever been 
> useful?

I was wondering the same. It's also very bug prone because when 
overriding the function you must remember to invoke the super method, a 
thing you can forget.



More information about the Digitalmars-d mailing list