[Issue 2525] override of function from abstract base class's interface

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 7 12:38:25 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=2525


Dicebot <public at dicebot.lv> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |public at dicebot.lv


--- Comment #4 from Dicebot <public at dicebot.lv> 2013-08-07 12:38:20 PDT ---
(In reply to comment #2)
> Technically you're not overriding, you're implementing. I think there is no bug
> here. I also think the following should be an error:
> 
> -----
> interface I
> {
>     void foo();
> }
> 
> class C : I
> {
>     override void foo () {}  // no error here currently
> }
> ----

Voting up this bug report.

Semantical difference between overriding and implementing is very subtle here.
One can also say that it overrides function with empty implementation.

However, what does matter here is pragmatical usability it brings to the table.

http://dlang.org/attribute.html#override
> The override attribute applies to virtual functions. It means that the
> function must override a function with the same name and parameters in a base
> class. The override attribute is useful for catching errors when a base
> class's member function gets its parameters changed, and all derived classes
> need to have their overriding functions updated. 

This description does miss one important use case - verifying that you do not
introduce a new function symbol in the class hierarchy. Consider this example:
in the process of wild refactoring interface signature changes and dependent
classes get modified. A sloppy programmer works on new implementation of that
functions and forgets that there is already existing one. However, code
compiles and works, polluting sources with unused function body.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list