I have a job to do related to CSV-files. First of all, I receive the file, then I split it up into rows. Then I split this rows into fields and I have an String-array of data. Now I have to read out certain data and create objects out of that data. If I do it straightforward, the code looks like this:
This code is not very nice to read, because there are literal constants in it. The easiest solution would be to create constants to "describe" the array:
But the class does not look nicer if I put about 40 such declarations in it. So I tried an enum:
Accessing the array now is even more complicated and does not bring more clarity to my code. It looks "bloated" instead:
And using the ordinal()-method might not be the idea of using enums. So using enums seems to be the wrong way.
Does anyone have an idea how I can seperate the code of my factory-method from the description of the array?