Delphi 接口(8)多重继承深入讨论

分享图片

分享图片

分享图片

 

 

 

unit uSayHello;

interface

uses    
    SysUtils,Windows,Messages,Greaphics,Controls,Forms,Dialogs;

type 
ISpeakLanguage = interface(IInterface)
    function SayHello: string;
end;

ISeakChinese = interface(ISpeakLanguage)
    //function SayHello: string;
end;

ISpeakEndlish = interface(ISpeakLanguage)
    //function SayHello: string;
end;

TMan = class(TInterfacedObject)
private
    FName: string;
public
    property Name: string read FName write FName;
end;

TChinese = class(TMan,ISpeakChinese)
private
    PSkinColor: string;
    function SayHello: string;
public
    constructor create;
    property SkinColor: TType read FSkinColor write FSkinColor;
end;

TAmerican = class(TMan,ISpeakEndlish)
    function SayHello: string;
end;

TAmericanChinese = class(TMan,ISpeakChinese,ISpeakEndlish)
public
    constructor create;
    function SayHello: string;
end;

implementation

function TAmerican.SayHello: string;
begin
  result := Hello!;
end;

function TChinese.SayHello: string;
begin
  result := 你好;
end;

function TAmericanChinese.create;
begin
  name := Tom Wang;
end;

function TChinese.create;
begin
  skincolor := yellow;
end;

function TAmericanChinese.SayHello : string;
var
    Dad:ISpeakChinese;
    Mum:ISpeakEndlish;
begin
  Dad := TChinese.create;
  Mum := TAmerican.create;
  result := Dad.SayHello + Mum.SayHello;
end;

end.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐