Abstract classes vs interfaces, casting from void*

John Colvin john.loughran.colvin at gmail.com
Sun Aug 11 20:32:14 UTC 2019


On Sunday, 11 August 2019 at 20:15:34 UTC, Alex wrote:
> On Sunday, 11 August 2019 at 16:05:20 UTC, John Colvin wrote:
>> I'm trying to narrow down exactly what patterns work with each 
>> and how they overlap.
>>
>> What I was trying to get at with the abstract method thing is 
>> that
>>
>> abstract class C
>> {
>>     void foo();
>> }
>>
>> is an abstract class with a non-abstract method, whose 
>> implementation is going to come from somewhere else (not a 
>> common pattern in D).
>>
>> class C
>> {
>>     abstract void foo();
>> }
>>
>> is an abstract class with an abstract method foo, which means 
>> you have to override it in a inheriting class to get a 
>> non-abstract class.
>
> As I see this, everything you wrote is correct. :)
>
> But you compared abstractness with interface usage, initially. 
> So... I would say, interfaces are more like the abstract method 
> case without any function body. But then, you will have to use 
> "override" all across the inherited classes.

Ok. So that means the difference is pretty subtle, give or take a 
few extra keywords.

Which leaves multiple inheritance as the only significant 
difference?

 From my perspective it looks like there are two massively 
overlapping features with some quite arbitrary feeling 
restrictions and differences. E.g. why can I not inherit from 
multiple 100% abstract empty classes? Wouldn't that be the same 
as inheriting from multiple interfaces?


More information about the Digitalmars-d-learn mailing list