Interface vs pure abstract class - speed.
Diggory
diggsey at googlemail.com
Sun May 12 11:00:09 PDT 2013
On Sunday, 12 May 2013 at 17:31:22 UTC, SundayMorningRunner wrote:
> Hello, let's say I have the choice between using an abstract
> class or an interface to declare a "plan", a "template" for the
> descendants.
>
> From the dmd compiler point of view, should I use the abstract
> class version (so I guess that for each method call, there will
> be a few MOV, in order to extract the relative address from the
> vmt before a CALL) or the interface version (are the CALL
> directly performed in this case). Are interface faster ? (to
> get the address used by the CALL).
>
> Thx.
I would expect abstract classes to be slightly faster (certainly
they shouldn't be slower), but the difference to be insignificant
compared to other factors.
Deriving from an abstract base class is a much stronger
relationship than implementing an interface, so it depends on
your situation. If your class is a "provider" (eg. it provides
some functionality such as being able to receive some event) then
an interface makes more sense. If your class is a type of
something (eg. a button is a type of gui control) then
inheritance makes more sense.
More information about the Digitalmars-d-learn
mailing list