The Non-Virtual Interface idiom in D

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Sep 29 10:23:16 PDT 2009


Bill Baxter wrote:
> On Tue, Sep 29, 2009 at 8:46 AM, Don <nospam at nospam.com> wrote:
>> Bill Baxter wrote:

>> And also, is this statement true?
>>>> since C++ programmers tend to "when in doubt, make it virtual"
>> Do they? (Might be true, but I don't remember ever hearing it anywhere
>> else).
> 
> They might in practice, but the current preaching I hear is to
> generally to make the slimmest and least virtual interface you can get
> away with.  Of course nobody would need to preach about such
> methodology if there weren't some contrary trend commonly seen out in
> the wild.

Well there are two considerations that are in tension. One is that an 
abstract interface should be sufficient for getting work done, and that 
pushes its size up. If interfaces are too slim, people tend to "extend" 
them on the implementation side and then cast down to implementation 
whenever they need to get anything done. That pushes the size of 
interfaces upwards.

The other consideration is that interfaces should be narrow such that 
they are not difficult to understand and implement.

So thinking of making an interface as small as possible or as 
comprehensive as possible may miss part of the tradeoffs involved.

NVI offers the ability to distinguish between the interface that must be 
implemented, and the interface that gets used.


Andrei



More information about the Digitalmars-d mailing list