[fpc-pascal] Extend multiple classes with same code

Jorge Aldo G. de F. Junior jagfj80 at gmail.com
Sat May 19 02:10:39 CEST 2012


You simply cant do it. Not even multiple inheritance would help you in
this case.

You will have to extend each class by hand.

Multiple inheritance would allow you to join back branches in the
class hierarchy, but in this case you want to add the same
functionality to multiple branches, but keep the branches separate
entities. This is impossible with current freepascal OOP and i dont
think this is even a good thing to have.

It could be done multi-class helper, kind of class helper that works
on multiple classes. But i dont even know of a language that has such
possibility (i dont know much languages anyway).

2012/5/18 Zaher Dirkey <parmaja at gmail.com>:
>
> On Fri, May 18, 2012 at 11:27 PM, Bernd <prof7bit at googlemail.com> wrote:
>>
>>
>> _B3 = class(T_A);
>> How about this:
>>
>> T_A = class(TObject);
>>
>> T_AX = class(T_A);    // <-- this class implements your extensions
>>
>> T_B1 = class(T_AX);  // TB_1 and
>> T_B2 = class(T_AX);  // TB_2 inherit it
>> T_B3 = class(T_A);
>>
>>
>
> I can't, in fact it is my mistak when i explained.
>
> B1 B2 is in the base unit like as A, i cant modify it, very strict.
>
> My projects is db layer, i have TmyCustomField,
> TmyFields=class(TmyCustomField) and TmyParams=class(TmyCustomField), that in
> the base unit.
>
> now i like to inherit both TmyFields and TmyParams to add functions work on
> Firebird, TmyFirebirdFields and TmyFirebirdParams, both have same functions
> to work on buffer SQLDA.
>
> Best Regards
> Zaher Dirkey
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list