IOpenDoor = interface
function Open: boolean
end;
THome = class(IOpenDoor)
function Open
end;
TCar = class(IOpenDoor)
function Open;
end;
var
AOpen: IOpenDoor;
begin
if xxx then AOpen := THome.Create
else AOpen := TCar.Create;
AOpen.Open();
end;
这个很像:
var
a:Tstrings
begin
a:=Tstringlist.create
end;