implement vs override

Worldeater worldeater at planet.earth
Sun Nov 2 12:05:31 UTC 2025


On Sunday, 2 November 2025 at 00:49:36 UTC, Peter C wrote:
> On Friday, 31 October 2025 at 23:36:57 UTC, Quirin Schroll 
> wrote:
>> [...]
>
> 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.
>   }
> }

the whole point of it is to not have to cast to interfaces, but 
just have the type behave a certain way.
just use plain old composition if and alias the methods if you 
want this.



More information about the Digitalmars-d mailing list