override and interface methods
Steven Schveighoffer
schveiguy at gmail.com
Mon Oct 29 15:30:27 UTC 2018
On 10/29/18 9:14 AM, FeepingCreature wrote:
> When overriding a class method, you are required to specify `override`,
> indicating you are redefining existing behavior.
>
> When implementing an interface method, override *can* be used but
> doesn't *have to* be used. This seems quite ambiguous and confusing. Am
> I overriding a method here? If yes, I should be required to use it. If
> not, I should not be *allowed* to use it.
>
> Thoughts?
I think it actually used to be an error (don't remember where it
changed, but it was probably an early compiler). If I recall correctly,
it was quite a pain to switch between base class or interface because
you'd have to go through and remove or add override.
What *definitely* changed, is that override used to be optional for base
class overrides, but it was changed to be required when you did
override. It may have been that the optional behavior was the same for
interfaces, but just left alone.
For sure, we can't add a requirement for override on an interface, as
you aren't exactly overriding an existing implementation. Too much code
is out there that does not specify override for interfaces.
-Steve
More information about the Digitalmars-d
mailing list