[fpc-pascal] Traits Proposal

Ryan Joseph genericptr at gmail.com
Wed Feb 10 21:17:36 CET 2021



> On Feb 10, 2021, at 12:40 PM, Martin Frb via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> type
>   TSomeTrait = trait 
>   public 
>     procedure DoTraitFoo; 
>   end; 
> 
>   TSomeClass = class(TObject)
>   private
>     trait: TSomeTrait; // whatever syntax is used so that the trait is added
>   public
>     SomeVal: Integer;
>     procedure DoSome;
>     procedure Dispatch(var message); override;
>   end;

if it's the simple then just set a reference to TSomeClass inside of TSomeTrait. If the trait doesn't know anything about the implementor then you indeed need to use a dispatch table or something. Can't this be solved with existing features?

btw, I don't think we should model this based on PHP, I just gave that as an example. The Swift model is much more simple and does 99% of what you want. I think that's what we should do for Pascal also.

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list