Should certain abstract classes be instantiable?

Lutger lutger.blijdestijn at gmail.com
Thu Oct 1 15:02:43 PDT 2009


Andrei Alexandrescu wrote:

> dsimcha wrote:
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s
>> article
>>> Jeremie Pelletier wrote:
>>>> Andrei Alexandrescu wrote:
>>>>> Consider:
>>>>>
>>>>> class A {
>>>>>     abstract void fun() {}
>>>>> }
>>>>>
>>>>> The class defines a function that is at the same time abstract (so it
>>>>> requires overriding in derivees) and has implementation.
>>>>>
>>>>> Currently the compiler disallows creation of objects of type A,
>>>>> although technically that is feasible given that A defines the
>>>>> abstract method.
>>>>>
>>>>> Should A be instantiable? What designs would that help or hinder?
>>>>>
>>>>>
>>>>> Andrei
>>>> What's the point of marking fun() abstract if it has an implementation,
>>>> I thought the compiler disallowed that.
>>> It may offer incomplete functionality that is to be reused and enhanced
>>> by descendants.
>>> Andrei
>> 
>> If you are in that situation, then don't declare the class abstract.  I
>> thought
>> the whole point of abstract classes was that they can't be instantiated. 
>> If it can be instantiated, then what does abstract even mean?
> 
> They can't be instantiated.
> 
> Andrei

Exactly, to return to your original question: if you allow abstract classes 
to be instantiable it hinders a design where a class is mandated to be a 
base class only with default implementations of all methods. 



More information about the Digitalmars-d mailing list