usayhello.pas

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

PAS
88
字号
unit uSayHello;

interface

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

type
  ISpeakChinese = interface (IInterface)
    function SayHello: string;
  end;
  
  ISpeakEnglish = interface (IInterface)
    function SayHello: string;
  end;
  
  TMan = class (TInterfacedObject)
  private
    FName: string;
  public
    property Name: string read FName write FName;
  end;
  
  TChinese = class (TMan, ISpeakChinese)
  private
    FSkinColor: string;
    function SayHello: string;
  public
    constructor create;
    property SkinColor: string read FSkinColor write FSkinColor;
  end;
  
  TAmerican = class (TMan, ISpeakEnglish)
  private
    function SayHello: string;
  end;
  
  TAmericanChinese = class (TChinese, ISpeakEnglish)
  public
    constructor create;
    function TomSayHello: string;
  end;
  
implementation

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

{
*********************************** TChinese ***********************************
}
constructor TChinese.create;
begin
  skincolor:='黄色';
end;

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

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

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

end.

⌨️ 快捷键说明

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