I don't understand what is it's purpose?People say it will prevent misuse as instance variable cannot be modified directly.What i think is- So what, if not directly,but still we can modify those instance variables through setters.
So we can still misuse it in the same way, so where's the advantage?
Also have a look at one more doubt i have,
Even in those cases where we do expose the members through get/set, there are several advantages to using methods rather than making the variables private.
Campbell Ritchie wrote:I am not sure you have understood it. You can provide getXXX methods for those instance fields which are used by other classes, and setXXX methods for fields which are set from other classes. Obviously you don’t always need both setXXX and getXXX methods for a particular field.
Thanks i completely understood what you meant, thanks for putting it in a nice and understandable manner .
Remember you may not always want set methods for every field.