Skip to main content

Timeline for Why do we need private variables?

Current License: CC BY-SA 3.0

7 events
when toggle format what by license comment
Jun 27, 2013 at 14:31 comment added Brian @delnan: Private fields do, in some languages, provide certain forms of security. For example, see Eric Lippert's answer to Do the access levels and modifiers (private, sealed, etc) serve a security purpose in C#?.
Apr 10, 2012 at 10:41 comment added user7043 @chakrit Yes, I didn't mean to imply you were wrong. I just wanted to promote that point.
Apr 10, 2012 at 10:39 comment added chakrit @delnan note the phrase "by accident" yeah maybe I should be more clear on that.
Apr 10, 2012 at 10:35 comment added user7043 @chakrit and others: Note that those who are really out to use your private fields and methods can do so (via reflection). private is less than "not primarily intended for security", it provides no "security" to speak of. It's just a strong hint (delivered through the compiler) not to access it.
Apr 10, 2012 at 5:55 comment added chakrit IMO it's also about communication between the lib author and the lib consumer. Public interface is like "use this" and privates are like "don't use that" except that in Java, you really cannot use it by accident if make it private so it's safer and clearer that way.
Apr 10, 2012 at 5:50 history edited Oleksi CC BY-SA 3.0
added 408 characters in body
Apr 10, 2012 at 5:41 history answered Oleksi CC BY-SA 3.0