Re: How to have smaller units
Vern via fpc-pascal <[email protected]> Sun, 30 Nov 2025 10:05:19 -0500
| Newsgroups | gmane.comp.compilers.free-pascal.general |
|---|---|
| Message-ID | <[email protected]> |
Well said Giuliano ! Regards Vern On 2025-11-30 07:49, Giuliano Colla via fpc-pascal wrote: > 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 - [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