• Post Reply Bookmark Topic Watch Topic
  • New Topic

why getter and setter methods  RSS feed

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every field has setter and getter methods.what is happening in this methods
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, that was so detailed...
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where you set and get . tell me simply
 
Aditya Keyal
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you already know that question's answer whats the point of asking. Secondly thats pure and basic common sense. If you want to ask from a design perspective then please elaborate on the question with the suitable alternative as to what do we use and why. Your question is too vague to be answered logically.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You question is not clear. Tell The Details
 
Samir Kureshi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a servlet specific question. Posting such question in this forum wont attract good response.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set and get methods allow access to private fields without "exposing" those fields. They may weaken encapsulation, but that can be minimised by putting controls in the methods.That version allows no control on which values are passed, nor controls on the use of the "f" reference after it has been returned.This second version ensures the value of i is always in a permitted range, as well as testing f for something or other. In either case, it throws an Exception with a nice error message so you can see what went wrong. You will also see that the returned f is cloned, so any manipulation of the clone does not affect this object.

There are different ways of handling such problems. For example, a copy constructor may be better than cloning. Note that i is a primitive, so there is no need to copy it when it is returned.

Agree with seetharaman venkatasamy that you ought to ask more details and with Samir Kureshi that you posted in the wrong place.
Aditya Keyal and Zandis Murāns: your responses are close to the line separating fair comment from rudeness.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!