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

📄 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
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -