[fpc-pascal] How to have smaller units
Guillermo Martínez Jiménez
gmartinez at burdjia.com
Sat Nov 29 12:43:44 CET 2025
Good morning,
What you are asking for is "friend classes", a concept from C++. I
admit it wasn't a very bad idea but I think it breaks the "Object"
philosophy. An object should be self-contained. If you think that an
object should access to the privacy of another object, then there's a
mistake in your design.
I have no idea about what are you doing but I'm pretty sure you can fix
this by using a different design; maybe to revise some patterns will
help you to find the way to do it more properly.
These are my two cents.
Guillermo "Ñuño" Marínez
El Fri, 28 Nov 2025 13:58:38 -0800
Amir via fpc-pascal <fpc-pascal at lists.freepascal.org> escribió:
> Hi,
>
> One of the main thing bothering me while developing projects in
> Pascal is that my units are getting huge in size! The main reason is
> that the nice property that the classes could access each other
> private members if they are defined in the same unit motivates/forces
> me to define a lot of classes in the same unit. Then, all the
> functions/procedures implementation must go into the same unit. I
> know I can use inc file but I do not like it! The other option is to
> use "Cracker" pattern, in Delphi, which is fine but seems like a hack!
>
> In C++, the concept of header files vs c++ files is helpful. In
> Golang, one could implement the functions for a class in several
> files, as long as they are in the same directory (namespace).
>
> Wondering if there is a solution for this in Object-Pascal?
>
> Best,
> Amir
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list