unit PrintableUnit;
{$mode objfpc}{$H+}
{$codepage UTF-8}
interface
uses
SysUtils;
type
IPrintable = interface
['{213B407F-DB00-43D4-BA3D-FA508D8F5373}']
procedure PrintInfo;
end;
TContact = class(TInterfacedObject, IPrintable)
strict private
FName: string;
FPhone: string;
public
constructor Create(const AName, APhone: string);
destructor Destroy; override;
procedure PrintInfo;
end;
TProduct = class(TInterfacedObject, IPrintable)
strict private
FTitle: string;
FPrice: Double;
public
constructor Create(const ATitle: string; APrice: Double);
destructor Destroy; override;
procedure PrintInfo;
end;
TLogEntry = class(TInterfacedObject, IPrintable)
strict private
FTimestamp: string;
FMessage: string;
public
constructor Create(const ATimestamp, AMessage: string);
destructor Destroy; override;
procedure PrintInfo;
end;
implementation
constructor TContact.Create(const AName, APhone: string);
begin
inherited Create;
FName := AName;
FPhone := APhone;
end;
destructor TContact.Destroy;
begin
WriteLn(' [Уничтожен: ', FName, ']');
inherited Destroy;
end;
procedure TContact.PrintInfo;
begin
WriteLn(' Контакт: ', FName, ' — ', FPhone);
end;
constructor TProduct.Create(const ATitle: string; APrice: Double);
begin
inherited Create;
FTitle := ATitle;
FPrice := APrice;
end;
destructor TProduct.Destroy;
begin
WriteLn(' [Уничтожен: ', FTitle, ']');
inherited Destroy;
end;
procedure TProduct.PrintInfo;
begin
WriteLn(' Товар: ', FTitle, ' — ', FormatFloat('0.00', FPrice), ' руб.');
end;
constructor TLogEntry.Create(const ATimestamp, AMessage: string);
begin
inherited Create;
FTimestamp := ATimestamp;
FMessage := AMessage;
end;
destructor TLogEntry.Destroy;
begin
WriteLn(' [Уничтожен: ', FMessage, ']');
inherited Destroy;
end;
procedure TLogEntry.PrintInfo;
begin
WriteLn(' [', FTimestamp, '] ', FMessage);
end;
end.