加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 09:54:32 所属栏目:大数据 来源:网络整理
导读:? ? ? unit uSayHello; interface uses SysUtils,Windows,Messages,Greaphics,Controls,Forms,Dialogs; type ISpeakLanguage = interface (IInterface) function SayHello: string ; end ;ISeakChinese = interface (ISpeakLanguage) // function SayHello:

?

?

?

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读