encapsulation

BCS ao at pathlink.com
Tue Mar 13 11:48:08 PDT 2007


Reply to arun,

> BCS Wrote:
> 
>> Reply to arun,
>> 
>>> 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 ????
>> Everything inside of a module (a.k.a. file) is visible to everything
>> else inside of that module.
>> 
> how is the concept of data hiding and encapsulation implemented in D
> ?????
> 

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.





More information about the Digitalmars-d mailing list