Originally posted by Deepu Gupta:
Could you please let me know the reason as well?
Well, one could argue getter/setter methods violate encapsulation principles, because they exists solely for the purpose of directly manipulating an object's internal state. Strictly speaking an object should only expose behavior that operates on its state on behalf of a client, instead of allowing the client to shuffle it's state field by field by means of accessor methods (possibly violating class invariants). However, in my opinion that's a very academic viewpoint. For example, the amount of libraries and tools alone that depend on the JavaBeans convention to function properly (or at all) makes strict adherence to this principle a virtual impossibility.
[ September 22, 2008: Message edited by: Jelle Klap ]
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.