implement vs override
Peter C
peterc at gmail.com
Sat Nov 1 00:13:18 UTC 2025
On Friday, 31 October 2025 at 23:49:06 UTC, Peter C wrote:
> On Friday, 31 October 2025 at 23:36:57 UTC, Quirin Schroll
> wrote:
>> On Friday, 31 October 2025 at 22:58:04 UTC, Peter C wrote:
>>> NOTE: It's just an idea, not a proposal.
>>>
>>> I'm a big fan of clarity in design.
>>>
>>> Clarity is what makes your design understandable and
>>> maintainable.
>>>
>>> 'implement' - implements an abstract/interface method -
>>> First-time definition
>>>
>>> 'override' - overrrides a concrete base method - Replaces or
>>> extends existing logic
>>
>> This is a good idea for nomenclature in documentation, but it
>> doesn't work with the language. You can implement an interface
>> method by inheriting from a class that defines the method
>> without the base class implementing the interface.
>
> ok. interesting...
>
> interface IGreeter
> {
> void greet();
> }
>
> class Base
> {
> void greet() {}
> // Really, there should be a complier error here.
> // e.g "Error: Method 'greet' matches both a base class and
> interface signature."
> // so ok...what to do here?? remove or rename?
> // I don't think Base should sucessfully compile under this
> circumstance.
> }
>
> class Derived : Base, IGreeter
> {
>
> }
oops.
interface IGreeter
{
void greet();
}
class Base
{
void greet() {}
}
class Derived : Base, IGreeter
{
// "Error: class Derived inherits a base class method that
matches IGreeter.greet(). Use an explicit interface declaration
to implement Greeter.greet()"
}
More information about the Digitalmars-d
mailing list