Should certain abstract classes be instantiable?

Jeremie Pelletier jeremiep at gmail.com
Thu Oct 1 16:43:38 PDT 2009


Lutger wrote:
> Andrei Alexandrescu wrote:
> 
>> 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
> 
> Then again, if it offers incomplete functionality why would you want it to 
> be instantiable? Instantiable should mean you can use this guy no? I tried 
> hard to think of a reason but can't find any.
> 

Exactly, I only mark members as abstract if they have no 
implementations, if any members have an incomplete implementation then i 
mark the class as abstract.

I never had any problems that way. Besides it just makes no sense to 
have an implemented member as abstract.



More information about the Digitalmars-d mailing list