Why do private member variables behaved like protected in the same module when creating deriving class?
12345swordy
alexanderheistermann at gmail.com
Fri Oct 26 22:36:53 UTC 2018
On Friday, 26 October 2018 at 22:00:21 UTC, Stanislav Blinov
wrote:
> On Friday, 26 October 2018 at 21:16:54 UTC, 12345swordy wrote:
>> [...]
>
>> [...]
>
> I'm not the guy who stomped in here demanding answers from a
> language author regarding false assumptions.
"who stomped in here". That is your imagination.
>>> [...]
>
>> [...]
> "protected" exists solely for classes, not modules.
It like you not even trying to understand what I am saying here.
>> [...]
>
> The word is "access", not "inherit".
I know what I meant when I use the word "inherit". Don't play coy
with me.
> But indeed, if you want child to have access to parent's state
> inaccessible to external code, you should use 'protected'.
> That's exactly how you can allow other people to access some of
> the sate even when they're inheriting in another module.
*sigh*
>
>> [...]
>
> It feels like you don't understand how inheritance works. A
> derived class *does* inherit *all* of the parent's guts
> irrespective of where they're defined relative to each other,
> or what visibility attributes they have. It's just that some of
> the guts may not be accessible to the derived class. Parent's
> private state doesn't magically disappear from the derived
> class' bits.
>
>> [...]
>
> How so?
What does "use the language as intended" mean anyway?
>> [...]
>
> This *is* about encapsulation, which in itself is about
> visibility. "private" is strong encapsulation, "public" is weak
> encapsulation, "protected" is the middle ground. But a unit of
> encapsulation in D is a module, not a class.
You are addressing a straw man still.
>> [...]
>
> Eh?
>
>>> [...]
>
>> [...]
>
> No. I'm explaining to you that your understanding of the spec
> is incorrect.
>
Or poor reading compensation.
>> [...]
>
> What was it that you said about strawmen?
You literally use the words "artificial restrictions"!
>
>> [...]
>
> "private" doesn't get rid of anything. It simply disallows
> access outside of module. At least in D that's what it does.
> Again, perhaps there's something wrong with your understanding
> of inheritance.
>> [...]
> Which is why you should've thought twice before demanding
> answers.
No, that is you failing to follow the conversation. I am done.
More information about the Digitalmars-d
mailing list