DELPHI的VCL源码有很多这样的例子。比如TMtsDataModule继承自TRemoteDataModule。
假设你基类实现的接口为IKissYou,其定义如下:
IKissYou = Interface(IInterface)
function Get_ConnectionString: WideString; safecall;
procedure Set_ConnectionString(const Value: WideString); safecall;
property ConnectionString: WideString read Get_ConnectionString write Set_ConnectionString;
类TKissYou实现IKissYou
TKissYou = class(TInterfaceObject, IKissYou)
protected
function Get_ConnectionString: WideString; safecall;
procedure Set_ConnectionString(const Value: WideString); safecall;
end;
项目中有许多其他的类是继承自这个基类的,比如,IKissYourMouth, IKissYourFace
IKissYourFace=interface(IKissYou)
procedure KissFace; safecall;
则类TKissYourFace只需要继承这个TKissYou即可自动获得父类的ConnectionString属性。
TKissYourFace=Class(TKissYou, IKissyourface)
procedure KissFace; safecall;
end;
procedure TKissYourFace.KissFace;
begin
if ConnectionString = 'A Pretty Girl' then
DoKissFace
else
DoNotKissFace;
end;