Overloading/Inheritance issue
Walter Bright
newshound1 at digitalmars.com
Fri Aug 3 21:43:16 PDT 2007
Derek Parnell wrote:
> This is intentional and is due to D's simplistic lookup rules. Basically, D
> will look for a matching signature only in the class it self and not in any
> parent classes (its a little more complex than this but ...)
Essentially, D's behavior here matches C++'s. Steve is asking for Java
style behavior. There are good arguments for both styles, and risks with
both.
I prefer the C++ style because:
1) One can get the Java style behavior by using the alias declaration as
outlined by Derek.
2) It avoids the problem of forgetting to override one of the base class
overloads, which can be a hidden source of bugs.
3) A new overload can be added to the base class without screwing up the
derived class.
4) Having overloads spread across the inheritance hierarchy makes the
source code resistant to visual audits. For any method call, you'll have
to look at EVERY base class to see if it has an overload that is a
better match.
5) I tend to view overloads as a tool that should be used sparingly, not
as a substitute for having to think up a new name. In that vein, having
a complex set of overloads is an indication that something might be
wrong with the design.
More information about the Digitalmars-d
mailing list