private method in interface

Michael Shulman viritrilbia at gmail.com
Fri Jun 3 11:13:26 PDT 2011


On Thu, Jun 2, 2011 at 11:55 PM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> I don't really like the idea of private functions being virtual
> by default though, so maybe your suggestion would be a good one.

Speaking as a newbie with very little D experience, the idea of
private functions being non-virtual would make perfect sense to me if
'private' meant restricted to a single class, as it does in C++.  The
situation of a derived class being able to override a private function
from an interface or base class, but not *call* the overridden
function, seems a bit weird and pointless; using 'protected' does make
more sense to me for that use case.

However, given that in D, 'private' only means restricted to a
*module*, it's less clear to me why private functions should be
singled out as non-virtual.  I might want certain methods to be
accessible only within a given module, but still allow them to be
overridden within a class hierarchy that exists entirely inside that
module.  Unless the point of view is that each class should always
exist in its own module?

Mike


More information about the Digitalmars-d-learn mailing list