Интерфейсы: различия между версиями

Материал из Вики проекта PascalABC.NET
Перейти к навигацииПерейти к поиску
(Новая: == Ссылки == *Особенности языка: продвинутый уровень *[http://pascalabc.net/ru/bazovyie-osobennosti-yazyika-i-bibliotek.html Сайт PascalAB...)
 
Нет описания правки
Строка 1: Строка 1:
<source lang="Delphi">type
  IShape = interface
    procedure Draw;
    property X: integer read;
    property Y: integer read;
  end;
  ICloneable = interface
    function Clone: Object;
  end;
  Point = class(IShape,ICloneable)
  private
    xx,yy: integer;
  public
    constructor Create(x,y: integer);
    begin
      xx := x; yy := y;
    end; 
    procedure Draw; begin end;
    property X: integer read xx;
    property Y: integer read yy;
    function Clone: Object;
    begin
      Result := new Point(xx,yy);
    end;
  end;
var
  p: Point := new Point(2,3);
  ish: IShape := p;    // Использование Point вместо IShape
  icl: ICloneable := p; // Использование Point вместо ICloneable
 
begin
  writeln(ish.X,' ',ish.Y);
  var p1: Point := Point(icl.Clone);
  p := nil;
  writeln(p1.X,' ',p1.Y);
  writeln(ish is Point);
  writeln(ish is ICloneable); // Cross cast!
end.</source>
== Ссылки ==
== Ссылки ==
*[[Особенности языка: продвинутый уровень]]
*[[Особенности языка: продвинутый уровень]]
*[http://pascalabc.net/ru/bazovyie-osobennosti-yazyika-i-bibliotek.html Сайт PascalABC.NET: Особенности языка]
*[http://pascalabc.net/ru/bazovyie-osobennosti-yazyika-i-bibliotek.html Сайт PascalABC.NET: Особенности языка]

Версия от 09:11, 16 января 2010

type
  IShape = interface
    procedure Draw;
    property X: integer read;
    property Y: integer read;
  end;

  ICloneable = interface
    function Clone: Object;
  end;

  Point = class(IShape,ICloneable)
  private
    xx,yy: integer;
  public
    constructor Create(x,y: integer);
    begin
      xx := x; yy := y;
    end;  
    procedure Draw; begin end;
    property X: integer read xx;
    property Y: integer read yy;
    function Clone: Object;
    begin
      Result := new Point(xx,yy);
    end;
  end;

var 
  p: Point := new Point(2,3);
  ish: IShape := p;     // Использование Point вместо IShape
  icl: ICloneable := p; // Использование Point вместо ICloneable
  
begin
  writeln(ish.X,' ',ish.Y);
  var p1: Point := Point(icl.Clone);
  p := nil;
  writeln(p1.X,' ',p1.Y);
  writeln(ish is Point);
  writeln(ish is ICloneable); // Cross cast!
end.

Ссылки