In short:
On startup of a Java/Android application, consider an array of data being initialised with hard coded values. Then, during runtime, a class can read from that data. The exact elements from the array that it will want to access are dependent on User input at runtime.
In detail:
Consider a crossword application. From a main screen, you select the crossword that you want to play. A Crossword (class), creates multiple Questions (class). To create a Question, it is initialised with two strings: 'question' and 'answer'. In order for the Crossword to create all of it's Questions, it needs to know which Questions belong to it. When a User selects a Crossword from a list, it gets passed an ID which will map to (perhaps) an element index of a multidimensional array, whereby each outer array represents a set of crossword questions, and each inner array represents the questions within that crossword. Similar to below:
Array(
// crossword 1
[0] => Array(
// question 1
[0] => Array(
[0] => 'question'
[1] => 'answer'
)
// question 2
[1] => Array(
[0] => 'question'
[1] => 'answer'
)
)
// crossword 2
[1] => Array(
// question 1
[0] => Array(
[0] => 'question'
[1] => 'answer'
)
// question 2
[1] => Array(
[0] => 'question'
[1] => 'answer'
)
)
)
OK, so User selects Crossword 1, I now create a Crossword object, create multiple Question objects by accessing index 1 of the global array. Something like:
Q1 = new Question(globalArr[1][0][0], globalArr[1][0][1]);
Q2 = new Question(globalArr[1][1][0], globalArr[1][1][1]);
My question:
I imagine (hope) there is a more elegant OOP solution to this. Assuming that there is, I would appreciate someone sharing their knowledge. Would a Singleton design come into play here?
The main goal here is making hard coded information about each question accessible to the entire application (or at least a class)