Originally posted by Gregg Bolinger:
If you don't indent to provide any logic in your getter method, some would argue that just making the variable public is good enough
someClass.logoutButton;
And then someone sets the reference to null, and all code breaks. Way to go!
You really want a getter only, no setter for this.
If you pass the entire object, you do run the risk that calling code changes things you definitely don't want them to. Changing the action / action handlers for buttons, changing the caption, it's all possible if they have full access to the button.
What I usually do is just create methods for all interaction I allow; only if I want to allow the changing of the caption would I create a method "setButtonText(
String text)". This way, you as a creator of your code still remain in charge of what happens to the object.