如何将接口名称映射到不同的方法名称?

Mas*_*ler 3 delphi interface

如果我有一个实现接口的对象,它默认将接口方法自动映射到具有相同名称和签名的类的方法.有没有办法覆盖它并将接口方法映射到具有相同签名但名称不同的方法?(这可能很有用,例如,如果我实现两个接口,这两个接口都有一个具有相同名称和签名的方法,我希望能够用它们做不同的事情.)

Lar*_*ens 10

这是Erwin答案的代码示例

type
  ISomeInterface = interface
    procedure SomeMethod;
  end;

  IOtherInterface = interface
    procedure SomeMethod;
  end;

  TSomeClass = class(TInterfacedObject, ISomeInterface, IOtherInterface)
  public
    procedure ISomeInterface.SomeMethod = SomeInterfaceSomeMethod;    
    procedure IOtherInterface.SomeMethod = OtherInterfaceSomeMethod;    

    procedure SomeMethod;                // TSomeClass.SomeMethod
    procedure SomeInterfaceSomeMethod;   // ISomeInterface.SomeMethod
    procedure OtherInterfaceSomeMethod;  // IOtherInterface.SomeMethod
  end;
Run Code Online (Sandbox Code Playgroud)


Erw*_*win 8

这确实是可能的.该技术称为方法解决条款.