接口的定义
IAnimal = Interface
['{7683C5DD-55EC-4F0B-A486-95052E7F3BA3}']
procedure makeSound();
end;
实现接口的类定义
TDog=class(TInterfacedObject,IAnimal)
procedure makeSound();
end;
TCat=class(TInterfacedObject,IAnimal)
procedure makeSound();
end;
类的实现
{ TDog }
procedure TDog.makeSound;
begin
showmessage('汪汪');
end;
{ TCat }
procedure TCat.makeSound;
begin
showMessage('喵喵');
end;
类的调用
animal:=TDog.Create;
animal.makeSound;
animal:=TCat.Create;
animal.makeSound;
网友评论