[fpc-pascal] How to have smaller units

Giuliano Colla giuliano.colla at fastwebnet.it
Sun Nov 30 13:49:13 CET 2025


Hi,

IMHO your basic problem is that you are trying to use objects in a way 
which contradict the basic object concept. The basic concept is to 
expose an interface and hide the implementation. Higher level code 
should be able to use objects without caring of implementation.
Private object members are just private, implementation dependent, and 
therefore should not be accessible. If they are, you are making your 
high level code dependent from object implementation, which is wrong.
If for some reasons you cannot rearrange your code in such a way as to 
be coherent with object philosophy, that means that you should not use 
objects. You're not obliged to.
An object is nothing else but a data structure, which includes in 
addition the procedures to deal with the data.
But you may write just data structures and procedures separately, and 
make whatever you need be accessible form whatever else you need. And if 
you don't want end users have the same rights, you just use an 
interface. Your code will be loaded at run time, and end users will only 
be able to access what the interface exposes.
That is the trick used by Lazarus, whose high level objects are 
implemented in a totally different way depending on the selected widgetset.
Just my two cents.

Giuliano

Il 28/11/25 22:58, Amir via fpc-pascal ha scritto:
> 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

-- 
Do not do to others as you would have them do to you.They might have different tastes.



More information about the fpc-pascal mailing list