digitalmars.D - encapsulation
- arun s (9/9) Mar 13 2007 class A {
- BCS (3/13) Mar 13 2007 Everything inside of a module (a.k.a. file) is visible to everything els...
- Lars Ivar Igesund (7/22) Mar 13 2007 It's a variation on C++ friends.
- arun s (2/19) Mar 13 2007 how is the concept of data hiding and encapsulation implemented in D ???...
- BCS (6/25) Mar 13 2007 If I understand correctly, the idea is to get rid of friend but still le...
- Frits van Bommel (6/10) Mar 13 2007 The clock on your computer seems to be an hour ahead...
- BCS (8/22) Mar 13 2007 Actually I have the correct time and time zone but I haven't patched my ...
- Pragma (5/31) Mar 13 2007 Oh, so that *was* you. Kudos for getting your submission in on one of t...
- torhu (19/24) Mar 13 2007 'friend' doesn't work they way you're implying here.
- BCS (7/19) Mar 13 2007 Yes, friend acts as an invitation, however there are no limitations on w...
- Pragma (16/37) Mar 13 2007 Simple. :) Use separate modules/files:
- David B. Held (5/17) Mar 22 2007 In D, 'private' really means 'package private', like Java's 'package'
- Chris Nicholson-Sauls (5/22) Mar 22 2007 Actually its module-private, with the seperate 'package' attribute provi...
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 ????
Mar 13 2007
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.
Mar 13 2007
BCS wrote:Reply to arun,It's a variation on C++ friends. -- Lars Ivar Igesund blog at http://larsivi.net DSource, #d.tango & #D: larsivi Dancing the Tangoclass 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.
Mar 13 2007
BCS Wrote:Reply to arun,how is the concept of data hiding and encapsulation implemented in D ?????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.
Mar 13 2007
Reply to arun,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.Reply to arun,how is the concept of data hiding and encapsulation implemented in D ?????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.
Mar 13 2007
BCS wrote:[stuff]with headers:Date: Tue, 13 Mar 2007 18:48:08 +0000 (UTC) X-Trace: [more numbers] (13 Mar 2007 17:48:15 GMT) NNTP-Posting-Date: Tue, 13 Mar 2007 17:48:15 +0000 (UTC)The clock on your computer seems to be an hour ahead... (Or you've already switched to Daylight Savings and forgot to set the right timezone your computer so it can correct accordingly when converting to UTC)
Mar 13 2007
Reply to Frits,BCS wrote:Actually I have the correct time and time zone but I haven't patched my system to be in sync with the new Daylight savings time. Last time I patched "Just because I can" I sent in the result to the dailyWTF <g> http://thedailywtf.com/Articles/Pop-up_Potpourri_0x3a__The_Re lly_Windy_City.aspx (at the bottom) If the date thing causes problems I'll do something about it.[stuff]with headers:Date: Tue, 13 Mar 2007 18:48:08 +0000 (UTC) X-Trace: [more numbers] (13 Mar 2007 17:48:15 GMT) NNTP-Posting-Date: Tue, 13 Mar 2007 17:48:15 +0000 (UTC)The clock on your computer seems to be an hour ahead... (Or you've already switched to Daylight Savings and forgot to set the right timezone your computer so it can correct accordingly when converting to UTC)
Mar 13 2007
BCS wrote:Reply to Frits,Oh, so that *was* you. Kudos for getting your submission in on one of the funnier WTF Potpourri's in a while. :) And yes, thank you for pressing Cancel. -- - EricAnderton at yahooBCS wrote:Actually I have the correct time and time zone but I haven't patched my system to be in sync with the new Daylight savings time. Last time I patched "Just because I can" I sent in the result to the dailyWTF <g> http://thedailywtf.com/Articles/Pop-up_Potpourri_0x3a__The_Re lly_Windy_City.aspx (at the bottom) If the date thing causes problems I'll do something about it.[stuff]with headers:Date: Tue, 13 Mar 2007 18:48:08 +0000 (UTC) X-Trace: [more numbers] (13 Mar 2007 17:48:15 GMT) NNTP-Posting-Date: Tue, 13 Mar 2007 17:48:15 +0000 (UTC)The clock on your computer seems to be an hour ahead... (Or you've already switched to Daylight Savings and forgot to set the right timezone your computer so it can correct accordingly when converting to UTC)
Mar 13 2007
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. From Stroustrup himself, at http://www.research.att.com/~bs/bs_faq2.html#friend --- Does "friend" violate encapsulation? No. It does not. "Friend" is an explicit mechanism for granting access, just like membership. You cannot (in a standard conforming program) grant yourself access to a class without modifying its source. For example: class X { int i; public: void m(); // grant X::m() access friend void f(X&); // grant f(X&) access // ... }; void X::m() { i++; /* X::m() can access X::i */ } void f(X& x) { x.i++; /* f(X&) can access X::i */ } ---
Mar 13 2007
Reply to torhu,BCS wrote: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.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.
Mar 13 2007
arun s wrote:BCS Wrote:Simple. :) Use separate modules/files: //test.d class A{ private int c = 0; } //main.d import test; void main(){ A a = new A(); printf("%d",a.c); }Reply to arun,how is the concept of data hiding and encapsulation implemented in D ?????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.dmd main test main.d(5): class test3.A member c is not accessibleYou're correct about using 'private' or even 'protected' for encapsulation. As others have stated, keeping everything in one file *implicitly* side-steps those rules. It's a very useful feature if exploited correctly. -- - EricAnderton at yahoo
Mar 13 2007
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
Mar 22 2007
David B. Held wrote:arun s wrote: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-Saulsclass 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
Mar 22 2007