Using closure in function scope to make "real" private class members

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Wed Jun 8 03:52:05 UTC 2022


On Tuesday, 7 June 2022 at 23:50:55 UTC, forkit wrote:
> On Tuesday, 7 June 2022 at 19:42:00 UTC, Ola Fosheim Grøstad 
> wrote:
>>
>> It is very difficult to get good usability as long as most 
>> users coming from other languages have a rather firm 
>> interpretation of what `private` means.
>
> No, they (we) come with a firm interpretation of what 
> encapsulation means, because they (we) can actually make things 
> private,

That is a weird take. The word can mean private to the file or 
module, whatever the language defines as the basic unit. Nothing 
wrong with that, just unusual in language design to use that word 
inside a class with that meaning.

> C++ friend is not something you should be using all the time. 
> It breaks encapsulation. It does not enhance it,

Actually, it often does in my code. I use it to prevent creation 
of the class outside the factory.



More information about the Digitalmars-d mailing list