⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usayhello.pas

📁 Delphi面向对象编程思想附书源码 好用哦!
💻 PAS
字号:
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
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -