Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Use getters and setters on static fields?

Posted on 2006-05-15
3
Medium Priority
?
330 Views
Last Modified: 2010-03-31
Dear Experts,

Is there an "industry standard" for accessing static fields?  I normally use private fields with getters and setters now.  But in the case of static fields, is it worthwhile to bother?  It seems a lot simpler to just do:

String myString = MyClass.SOME_STATIC_FIELD;

and declare SOME_STATIC_FIELD to be public and final.

Thanks,
BrianMc1958
0
Comment
Question by:BrianMc1958
3 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 16683838
The rules for static fields are exactly the same as for instance fields.
Access restrictions and checking of set-values are just the same!

;JOOP!
0
 
LVL 92

Accepted Solution

by:
objects earned 120 total points
ID: 16686163
> and declare SOME_STATIC_FIELD to be public and final.

In that case its a constant so doesn't need a setter, so making it public is acceptable.
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 80 total points
ID: 16688064
Abstraction and encapsulation make more sense for data-members, not for static stuff which needs to be publicly accessible.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question