Very hacky solution to class private members

Prezelboss no at no.no
Thu Jun 9 13:20:08 UTC 2022


On Thursday, 9 June 2022 at 12:42:22 UTC, forkit wrote:
> On Thursday, 9 June 2022 at 10:03:02 UTC, Dom Disc wrote:
>> [...]
>
> Well, it's not necessarily better - either way.
>
> If I can encapsulate one concept well, within a class, why must 
> I be forced to expand my 'encapsulation barrier' to the module.
>
> What have I achieved in doing that?
>
> I mean even a function in a module has a better encapsulation 
> barrier than a class! Well, even an int does - you can't just 
> put "wtf!" into an int. An int has a set of invariants that 
> must be maintained, and are, by the compiler.
>
> Smaller abstraction are easier to reason about too.
>
> An encapsulation barrier at the module level, is also very 
> useful.
>
> But it should be your design decision, not the language forcing 
> it onto you.
>
> With the proper access levels (i.e scope level privacy), the 
> problem just goes away...no need to do silly workarounds.

If you don't want members to be visible to the whole module, why 
do you insist on putting the class definition into the module 
scope in the first place? just put it inside a function.


More information about the Digitalmars-d mailing list