Is it bad programming practice to use Static Variables for accessing data?
Hello, I have recently written a program in Swing, however, I have yet to actually put any real data values in yet.
The plan was, I was going to make another Class filled with all my data values and just makes all the Values static to save me time.
I've always been told to avoid Static variables, but in terms of accessing data is it a bad idea? The rest of my swing code I have yet to use any Static variables and have relied on inheritance/Interfaces to access objects from other classes.
Re: Is it bad programming practice to use Static Variables for accessing data?
Java is object oriented; static members should generally be limited to constants and utility methods. Also generally, data comprises state, and should not be static.
Inheritance should not be misused to gain access to members of another class. The key to a properly designed inheritance hierarchy is the "is-a" Using the Swing hierarchy as an example, a JLabel is-a JComponent with added functionality; if your subclass does not fulfill the is-a relationship of its superclass, that's misuse of inheritance. Pass references around instead and call methods of the other class to access its state.
If I haven't expressed that clearly enough (I'm not a programmer and have absolutely no qualifications in CS), ask and another more qualified member will surely step in to fill the gaps.