[fpc-pascal] Traits Proposal

gabor gabor at poczta.onet.pl
Sun Feb 14 00:17:37 CET 2021


W dniu 2021-02-13 o 20:38, Sven Barth via fpc-pascal pisze:
> Of course this does not provide any mechanism to directly add fields, 
> however the compiler could in theory optimize access through property 
> getters/setters if they're accessed through the surrounding class 
> instance instead of the interface.

So the complement could be generic classes like this:

type
   generic TTestGeneric = class(<TAncenstorClass>, ITest, IInterface2)
   private
     fTest: TTestImpl;
   public
     property Test: TTestImpl read fTest implements ITest; default;
   end;

   TMyTest = specialize TTestGeneric(<TInheritedCalssOfTAncesot>);

Something similar has already been asked:
https://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg53599.html

Michał.


More information about the fpc-pascal mailing list