[fpc-pascal] Extend multiple classes with same code

Michael Van Canneyt michael at freepascal.org
Fri May 18 21:18:12 CEST 2012



On Fri, 18 May 2012, Zaher Dirkey wrote:

> Hi,
> 
> I have 2 objects inherited from the base one
> 
> T_A = class(TObject);
> 
> T_B1 = class(T_A);
> T_B2 = class(T_A);
> T_B3 = class(T_A);
> 
> Now if I want to extend T_B1 it is easy to inherit it to T_C1 = class (T_B1) and add many functions to it, but.
> 
> I want the same extend T_B2  not T_B3,
> 
> 1 - The first idea is adding this functions to T_A, but it is not my class to modify it, or it is protected from my modify.
> 2 - Copy and paste this functions to T_B2, but in that case I need every time to fix functions in B1 I must do it in B2, that make it so hard, and not good
> programming quality.
> 
> Is there any new idea to do that, what about Helper, generics, i read about it i felt it is not fit to my problem (or i am wrong).

Maybe you can try interfaces and interface delegation.

Michael.


More information about the fpc-pascal mailing list