以前没想过这个问题,只知道接口中的方法不带可见度说明符,都是public的,原来DELPHI类在实现接口时,可以任意的升降接口方法的可见度。
IMyInterface=interface(IInterface)
procedure p1;
procedure p2;
end;
TMyClass = class(TinterfacedObject,IMyInterface)
private
FmyValue:integer;
procedure p1;
protected
procedure myMethod;
public
procedure IMyInterface.p2 = MyMethod;
published
end;
implementation
{ TMyClass }
procedure TMyClass.myMethod;
begin
showmessage('MyMethod');
end;
procedure TMyClass.p1;
begin
showmessage('I comes from Interface.');
end;
如上代码,可以直接将方法实现为任意可见度,也可以用方法决定子句。