Mostly I agree, mainly because they support better encapsulation. That is you can add additional logic into the getters and setters (for example to perform validation, data formatting etc) which don't need to be visible to other classes (or even within the same class).

There is a (albeit slight) performance hit with using getters and setters, so there are times where direct access to instance variables is a good thing. I'd also consider the value of them for use within Nested Classes a bit limited.

Brenden



miga <[email protected]>
Sent by: [email protected]

21/01/2009 04:11 PM

Please respond to
[email protected]

To
Free Java Programming Online Training Course By Sang Shin <[email protected]>
cc
Subject
[java programming] Re: Use of "Getter/Setter" Methods inside of a Class








On Jan 21, 7:03 am, BillyRay <[email protected]> wrote:

> What are the rules or guidelines for deciding when it is appropriate
> to use the getter/setter methods to access instance variables in
> another method inside of a class versus accessing the variables
> directly?
It is always better to access variables with getter and setter
methods. This way, you ensure they cannot be accessed directly. If you
use Netbeans, there is a refactor task which allows you to transform
your code to always do that.


This email is sent by Australian Insurance Holdings Pty Ltd or a related body corporate (AIH) and is for the intended addressee. 
The views expressed in this email and attachments (email) reflect the views of the stated author but may not reflect views of AIH. 
This email is confidential and subject to copyright. It may be privileged. If you are not the intended addressee, confidentiality 
and privilege have not been waived and any use, interference with, or disclosure of this email is unauthorised. If you are not the 
intended addressee please immediately notify the sender and then delete the email. AIH does not warrant that this email is error or 
virus free.


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to