[fpc-pascal] Traits Proposal
Ryan Joseph
genericptr at gmail.com
Fri Feb 19 16:50:51 CET 2021
> On Feb 18, 2021, at 11:30 PM, Sven Barth <pascaldragon at googlemail.com> wrote:
>
> The only thing that will not work and which will continue not to work is that m_circle.Draw will not be called if you access the TMyShape through a TShape.Draw call. For that one needs to use an explicit declaration:
>
> === code begin ===
>
> type
> TMyShape = class(TShape, ICircle)
> private
> m_circle: TCircle;
> public
> procedure ICircle.Draw = Draw;
> property Circle: TCircle read m_circle implements ICircle;
> procedure Draw; override;
> end;
>
> procedure TMyShape.Draw;
> begin
> m_circle.Draw;
> end;
>
> === code end ===
So the method resolution doesn't actually change the VMT table of the class, just the interface? That's unfortunate because being able to affect the VMT by method resolution would open up a lot of possibilities for polymorphism using composition. Maybe writing wrapper functions is good enough for this. Not sure, I need to do some research into old code and explore things a bit more.
I just realized another potential problem. If we use the "default" keyword that means there could be multiple "defaults" unless we limit the property to 1 per class, which would kind of defeat the purpose of the feature (like the issue we had with helpers and made multi-helpers for).
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list