March 13, 2007 Re: encapsulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to torhu | Reply to torhu,
> BCS wrote:
>
>> If I understand correctly, the idea is to get rid of friend but still
>> let some things look inside of others. This solution lets closed set
>> of code interact at a low level while doing encapsulation at wider
>> scopes. The reason friend is discarded is that it has the power to do
>> arbitrary snooping which causes the same kind of problems as goto's
>> arbitrary redirection causes.
>>
> 'friend' doesn't work they way you're implying here.
>
>
Yes, friend acts as an invitation, however there are no limitations on who a class can invite. This is "arbitrary snooping" I was talking about. With D's private semantics, that same "you can look at my private stuff" ability is limited to a finite set of code. It is somewhat like how goto can go to most anywhere in a function but labeled break and continues can only go to the start or end of a loop.
|
March 22, 2007 Re: encapsulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to arun s | arun s wrote:
> class A { private int c=0; }
>
>
> void main() {
> A a = new A();
> printf("%d",a.c);
> }
>
> consider the above code snippet..... y there is no error in printf statement a.c , since attribute "c" is private ????
In D, 'private' really means 'package private', like Java's 'package' visibility (or 'default' visibility), not like C++'s 'private'. While I prefer tight visibility semantics, I think this is a reasonable compromise.
Dave
|
March 22, 2007 Re: encapsulation | ||||
---|---|---|---|---|
| ||||
Posted in reply to David B. Held | David B. Held wrote:
> arun s wrote:
>> class A { private int c=0; }
>>
>>
>> void main() {
>> A a = new A();
>> printf("%d",a.c);
>> }
>>
>> consider the above code snippet..... y there is no error in printf statement a.c , since attribute "c" is private ????
>
> In D, 'private' really means 'package private', like Java's 'package' visibility (or 'default' visibility), not like C++'s 'private'. While I prefer tight visibility semantics, I think this is a reasonable compromise.
>
> Dave
Actually its module-private, with the seperate 'package' attribute providing package-level visibility. Unfortunately 'package' currently suffers in that such declerations are hidden from sub-packages.
-- Chris Nicholson-Sauls
|
Copyright © 1999-2021 by the D Language Foundation