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

forkit forkit at gmail.com
Wed Jun 8 00:12:28 UTC 2022


On Monday, 6 June 2022 at 11:45:31 UTC, Dom Disc wrote:
> On Monday, 6 June 2022 at 02:35:11 UTC, forkit wrote:
>> On Monday, 6 June 2022 at 01:23:41 UTC, forkit wrote:
>>>
>>
>> when your boss isn't really your friend:
>>
>> // ----
>>
>> module test;
>> @safe :
>>
>> class Employee
>> {
>> }
>>
>> class Boss
>> {
>> }
>>
> Now that is real nonsense! Why should those two classes ever be 
> within the same file?!?
>

The two classes were clearly concocted for the example - 
actually, after a discussion with a friend about problems they 
were having with their boss - who pretended to be friend to them, 
until one day ....

But that aside, it is often that one object cannot exist, unless 
the other object already exists.

It's not unusual, to want to keep this code together - even, god 
forbid, in the same module!

> Not everything is a friend - only what is in the same file!

Precisely. That's my whole point. Everything in the same file is 
your friend. Although, that is not the actual problem, since 
friends are useful. The actual problem is there is 'no option to 
unfriend'.

There are no encapsulated components in a module. The D language 
doesn't provide the means to do that. It's all just one big... 
thing.




More information about the Digitalmars-d mailing list