Very hacky solution to class private members

forkit forkit at gmail.com
Thu Jun 9 12:42:22 UTC 2022


On Thursday, 9 June 2022 at 10:03:02 UTC, Dom Disc wrote:
>
> ...
> I still don't get why class level encapsulation should be any 
> better than module level encapsulation.

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.



More information about the Digitalmars-d mailing list