PDA

View Full Version : java - Access to Members



Geir102
June 20th, 2008, 07:33 PM
Hi! I'm learning java. And I've read that declearning evrything public is not a good idea.. Can any one tell my way? Is it a securety risk?

mike_g
June 20th, 2008, 07:52 PM
Its for encapsulation. Its not specifically a security risk; the basic idea behind it is to reduce bugs. It does tend to bring a lot of verbose code with it as well with all those 'get', 'set' function. It took me a little while to get the point of it all.

Geir102
June 20th, 2008, 08:08 PM
tanks:popcorn:

MacUntu
June 21st, 2008, 01:28 PM
It's more about design than encapsulation I'd say. Objects don't need to know more about other objects than necessary.

Every object has its function, its responsibility. Other objects only need to know that those functions/responsibilities exist but nothing about their implementation or the objects inner structur.

[h2o]
June 23rd, 2008, 08:09 PM
I found this article to be an eye-opener regarding abstraction and setters/getter-functions in Java: http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html