Inheritance from multiple interfaces with the same method name
Pham
home at home.com
Thu Dec 7 00:26:49 UTC 2017
On Wednesday, 6 December 2017 at 23:56:33 UTC, Q. Schroll wrote:
> Say I have two interfaces
> interface I { void f(); }
> and
> interface J { int f(); }
> implemented by some class
> class A : I, J {
> // challenge by the compiler:
> // implement f()!
> }
>
> VB.NET allows that by renaming the implementation (it does
> allow it generally, not only in the corner case).
> C# allows that by specifying the target interface when
> implementing (can be omitted for exactly one; corner case
> handling); the specification makes the implementation private.
> (See [1])
> Java just disallows the case when two methods are incompatible.
> If they are compatible, they must be implemented by the same
> method. If they are meant to do different things, you are
> screwed.
>
> What is D's position on that? The interface spec [2] does not
> say anything about that case.
>
>
> [1]
> https://stackoverflow.com/questions/2371178/inheritance-from-multiple-interfaces-with-the-same-method-name
> [2] https://dlang.org/spec/interface.html
Delphi resolves this with below syntax; I think it's clean and
simple
Pham
class A : I, J
{
// Define function for each interface
void I_f() {}
int J_f() {}
// Assign function to interface
I.f = I_f;
J.f = J_f;
}
More information about the Digitalmars-d
mailing list