implement vs override

Peter C peterc at gmail.com
Sun Nov 2 00:49:36 UTC 2025


On Friday, 31 October 2025 at 23:36:57 UTC, Quirin Schroll wrote:
>
> ...
> 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.

If D had a C# like 'explicit' interface declaration:

module myModule;
@safe:
private:

void main()
{

}

interface Isomething
{
     void someMethod();
}

class Base
{

     void someMethod()
     {

     }
}

class Derived : Base, Isomething
{
   // Here, I am intentionally binding the interface requirement
   // to a concrete method, rather than letting the inherited 
method automatically
   // fulfill the interface contract.

   void ISomething.SomeMethod()
   {
     // This method satisfies the interface, but it's only 
accessible
     // when the object is cast to the ISomething type.
   }
}



More information about the Digitalmars-d mailing list