I am creating instances of a class with extends Button and accessing an integer variable directly for better performance. I'm using constants to easily identify the variable's current setting.
I have the constants declared both the Button class and in the Activity class which is instantiating them. I have found similar questions and read it's not good practice to create a class just to hold constants.
What is the best way to use the same constant declaration in both classes?
I am a beginner programmer so it's quite possible I am overlooking a simple solution.
Button class:
public class GridButton extends Button {
public int displayStatus;
// constants for mine display status
private static final int UNTOUCHED = 1;
private static final int UNCOVERED = 2;
private static final int FLAGGED = 3;
private static final int HIT = 4;
...
}
Activity class:
public class PlayGameActivity extends Activity {
private GridButton[][] gridButtons;
// constants for mine display status
private static final int UNTOUCHED = 1;
private static final int UNCOVERED = 2;
private static final int FLAGGED = 3;
private static final int HIT = 4;
...
// e.g. accessing displayStatus value
if (gridButtons[currentRow][currentColumn].displayStatus == FLAGGED)
{
}
}