usayhello.pas

来自「Delphi面向对象编程思想附书源码 好用哦!」· PAS 代码 · 共 81 行

PAS
81
字号
unit uSayHello;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs;

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

  ISpeakChinese = interface (ISpeakLanguage)
    //function SayHello: string;
  end;
  
  ISpeakEnglish = 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
    function SayHello: string;
  end;
  
  TAmerican = class (TMan, ISpeakEnglish)
  private
    function SayHello: string;
  end;
  
  TAmericanChinese = class (TMan, ISpeakChinese, ISpeakEnglish)
  public
    constructor create;
    function SayHello: string;
  end;

implementation

{
********************************** TAmerican ***********************************
}
function TAmerican.SayHello: string;
begin
  result:='Hello!';
end;
{
*********************************** TChinese ***********************************
}
function TChinese.SayHello: string;
begin
  result:='你好!';
end;

{
******************************* TAmericanChinese *******************************
}
constructor TAmericanChinese.create;
begin
  name:='Tom Wang';
end;

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

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?