Adding Modules to C in 10 Lines of Code

Dom Disc dominikus at scherkl.de
Mon Jun 6 11:25:40 UTC 2022


On Monday, 6 June 2022 at 03:17:34 UTC, forkit wrote:
> cannot have encapsulation unless it is put into a super type
> (the module), all by its self (with no friends).

It can have friends - they just need to be in the same file 
(module).
And a class without its friend is really only half a type - 
that's why it is better to think of the module as the new type - 
which contains both the interface and all interna (friends and 
sub-classes and @system parts that should not be visible from the 
outside).

That's what a file is for in general: to collect things that 
belong together and should be seen as a single object. It makes 
no sense to put other unrelated classes or functions into the 
same file. Especially not in a large project (which is the only 
case where encapsulation makes sense at all).


More information about the Digitalmars-d-announce mailing list