unit Unit2;
interface
uses
System.Classes;
type
TFoo =
class abstract( TPersistent )
protected
procedure AssignTo( Dest: TPersistent );
override;
public
constructor Create( );
constructor CreateFrom( Other: TFoo );
end;
TAdvancedFoo =
class( TFoo )
private
FFirstName:
string;
procedure AssignTo( Other: TAdvancedFoo );
overload;
protected
procedure AssignTo( Dest: TPersistent );
overload;
override;
public
property FirstName:
string read FFirstName
write FFirstName;
end;
TMoreAdvancedFoo =
class( TAdvancedFoo )
private
FLastName:
string;
procedure AssignTo( Other: TMoreAdvancedFoo );
overload;
protected
procedure AssignTo( Dest: TPersistent );
overload;
override;
public
property LastName:
string read FLastName
write FLastName;
end;
implementation
{ TFoo }
procedure TFoo.AssignTo( Dest: TPersistent );
begin
if Dest
is TFoo
then
else
inherited;
end;
constructor TFoo.Create;
begin
inherited;
end;
constructor TFoo.CreateFrom( Other: TFoo );
begin
Create;
Self.Assign( Other );
end;
{ TAdvancedFoo }
procedure TAdvancedFoo.AssignTo( Dest: TPersistent );
begin
inherited;
if Dest
is TAdvancedFoo
then
AssignTo( Dest
as TAdvancedFoo );
end;
procedure TAdvancedFoo.AssignTo( Other: TAdvancedFoo );
begin
Other.FFirstName := Self.FFirstName;
end;
{ TMoreAdvancedFoo }
procedure TMoreAdvancedFoo.AssignTo( Other: TMoreAdvancedFoo );
begin
Other.FLastName := Self.FLastName;
end;
procedure TMoreAdvancedFoo.AssignTo( Dest: TPersistent );
begin
inherited;
if Dest
is TMoreAdvancedFoo
then
AssignTo( Dest
as TMoreAdvancedFoo );
end;
end.