Разработка классов на языке Object Pascal. Соколов Е.В. - 74 стр.

UptoLike

Составители: 

74
function Slash (n: Number): Number; virtual;
function IsEqual(n: Number): Boolean; virtual; abstract;
procedure Add (n: Number); virtual; abstract;
procedure Subtract (n: Number); virtual; abstract;
procedure MultiplyBy(n: Number); virtual; abstract;
procedure DivideBy (n: Number); virtual; abstract;
procedure Assign (n: Number); virtual; abstract;
function AsString: String; virtual; abstract;
constructor Create; virtual;
constructor CreateEqualTo(n: Number); virtual;
end;
ClassNumber = class of Number;
implementation
function Number.Plus(n: Number): Number;
begin
result:=ClassNumber(self.ClassType).CreateEqualTo(self);
result.Add(n);
end;
function Number.Minus(n: Number): Number;
begin
result:=ClassNumber(self.ClassType).CreateEqualTo(self);
result.Subtract(n);
end;
function Number.Dot(n: Number): Number;
begin
result:=ClassNumber(self.ClassType).CreateEqualTo(self);
result.MultiplyBy(n);
end;
function Number.Slash(n: Number): Number;
begin
result:=ClassNumber(self.ClassType).CreateEqualTo(self);
result.DivideBy(n);
end;
constructor Number.Create;
begin
inherited Create;
end;
constructor Number.CreateEqualTo(n: Number);
begin
inherited Create; self.Assign(n);
end;
end.
    function      Slash (n: Number): Number;     virtual;
    function      IsEqual(n: Number): Boolean;   virtual;   abstract;
    procedure     Add       (n: Number);         virtual;   abstract;
    procedure     Subtract (n: Number);          virtual;   abstract;
    procedure     MultiplyBy(n: Number);         virtual;   abstract;
    procedure     DivideBy (n: Number);          virtual;   abstract;
    procedure     Assign    (n: Number);         virtual;   abstract;
    function      AsString: String;              virtual;   abstract;
    constructor   Create;                        virtual;
    constructor   CreateEqualTo(n: Number);      virtual;
  end;
  ClassNumber =   class of Number;
implementation
function Number.Plus(n: Number): Number;
begin
  result:=ClassNumber(self.ClassType).CreateEqualTo(self);
  result.Add(n);
end;
function Number.Minus(n: Number): Number;
begin
  result:=ClassNumber(self.ClassType).CreateEqualTo(self);
  result.Subtract(n);
end;
function Number.Dot(n: Number): Number;
begin
  result:=ClassNumber(self.ClassType).CreateEqualTo(self);
  result.MultiplyBy(n);
end;
function Number.Slash(n: Number): Number;
begin
  result:=ClassNumber(self.ClassType).CreateEqualTo(self);
  result.DivideBy(n);
end;
constructor Number.Create;
begin
  inherited Create;
end;
constructor Number.CreateEqualTo(n: Number);
begin
  inherited Create; self.Assign(n);
end;
end.




                                     74