The Non-Virtual Interface idiom in D

Don nospam at nospam.com
Tue Sep 29 04:04:37 PDT 2009


Andrei Alexandrescu wrote:
> In this article:
> 
> http://www.gotw.ca/publications/mill18.htm
> 
> Herb Sutter makes a powerful argument that overridable functions 
> (customization points) should actually not be the same as the publically 
> available interface. This view rhymes with the Template Method pattern 
> as well.

Ever since I read that earlier this year, I've wondered about this (from 
the spec):

"All non-static non-private non-template member functions are virtual. 
This may sound inefficient, but since the D compiler knows all of the 
class hierarchy when generating code, all functions that are not 
overridden can be optimized to be non-virtual. In fact, since C++ 
programmers tend to "when in doubt, make it virtual", the D way of "make 
it virtual unless we can prove it can be made non-virtual" results, on 
average, in many more direct function calls."

Based on what Herb says, D is actively encouraging bad design...



More information about the Digitalmars-d mailing list