Defining the elements as public (or having public getters/setters) allows anyone who initializes the class to set/update the values. This is what I do not want. I just want the other class(es) defined in the same unit to be able to do so.

On 11/28/25 2:27 PM, Tomas Hajny via fpc-pascal wrote:
On 2025-11-28 22:58, Amir via fpc-pascal wrote:


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?

What prevents you from declaring the class members as public if you want/need to access them from other classes? What prevents you from using (public) getters/setters and/or other methods instead of accessing the members directly?

Tomas
_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to