implement vs override
Peter C
peterc at gmail.com
Fri Oct 31 23:33:44 UTC 2025
On Friday, 31 October 2025 at 22:58:04 UTC, Peter C wrote:
>
or even (a C# like explicit implementation would be a nice option
to have in D:
interface Clickable
{
void onClick();
}
class Component
{
void render()
{
writeln("Rendering generic component");
}
}
class Button : Component, Clickable
{
void Clickable:onClick()
{
// First-time implementation of Clickable.onClick
writeln("Button clicked!");
}
override void render()
{
// Overrides Component.render
writeln("Rendering a button");
}
}
--- And when it becomes even more confusing:
interface Isomething
{
void someMethod();
}
class Base
{
void someMethod() { }
}
class Derived : Base, Isomething
{
override void someMethod() { } // ??
// Error: Method 'someMethod' matches both a base class and
interface signature. Use override or explicit interface
implementation to clarify."
}
More information about the Digitalmars-d
mailing list