Interfaces do not seem to be the ideal choice for me. I would still need to rewrite everything my BaseClass has for every other class right ?
No, everything from your base class will be inherited.
Just methods you want to
change in child classes need to be marked with virtual and subs overload:
{$mode objfpc}
type
THello= class
public
procedure Doit;virtual;
end;
TWorld = class(THello)
public
procedure Doit;override;
end;
THelloWorld = class(TWorld)
public
procedure Doit;override;
end;
procedure THello.Doit;
begin
write('Hello');
end;
procedure TWorld.Doit;
begin
inherited;
writeln(', world');
end;
procedure THelloWorld.Doit;
begin
inherited;
writeln('Goodbye');
end;
var
Hello,World,HelloWorld:THello;
begin
Hello := THello.Create;
World := TWorld.Create;
HelloWorld := THelloWorld.Create;
Hello.Doit;
writeln;
World.DoIt;
HelloWorld.DoIt;
HelloWorld.Free;
World.Free;
Hello.Free;
end.
That is a common misconception.
Override can of course also be used to change the behavior of a virtual method completely if you leave out the inherited calls.
Again, you do not need to repeat all implementation, just what needs to change.
BTW: parameterless constructors can not be virtual without a trick: they need to be virtual;reintroduce; to avoid warnings and it is advised to call inherited in that virtual one.