Privacy leakage
I have written a number of classes that extend and access each other, i know little bits of privacy leakage but was wondering if any one can tell me a bit about it to see if my classes have any instances of it. My classes have a number of setters and getters and copy constructors so i just want to know the best way to check that no value can be changed or accessed without using my definations.
[403 byte] By [
ajrobson] at [2007-11-26 12:03:28]

A general strategy I use (although I haven't made many large scale programs that involve many classes) is to make all class variables private, providing appropriate getters and setters (as you mentioned) that make sure values are set to appropriate domains. It seems like making as much private as you can not only would prevent privacy leakage but also make the api simpler to use (i.e. less options for interface).
~ericode
And if you want something to be changed only through your interface, make sure you never return it directly.
For example if you have a List as a member and don't want things to be added to it from outside that class, have the getter return an unmodifiable List instead so it's readonly.
return Collections.unmodifiableList(list);
instead of return list;
For other references you may want to return a clone instead of the thing itself.