Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getters and setters, please help

Status
Not open for further replies.

sophia03

Programmer
Apr 12, 2004
9
US
Can somebody give me an example of getters and setters or where I can go to learn more about them? I really appreciate the help. Thanks.
 
There are two schools of thought on their use. School 1 (which I follow) says:
Get/Set form part of the API of a class. The getter/setters are there to help define how a class should be used. They also abstract the public face of a class from it's internal messy details. Sure, for the most part, they're just wrappers for private member variables, but when you need to perform some type checking, permission checking, etc, they provide a good place for that to happen.

School 2 says:
Get/Set just take up CPU cycles. This school says that unless you really need a getter/setter, you're better off using a public member variable. Having to enter a getter/setter in order to retrieve a value just wastes time. See (no java in the article -- it's just talking about O-O design issues).

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top