Forums Register Login

"Describing" an array

+Pie Number of slices to send: Send
Hi there

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?

Thank you!
What? What, what, what? What what tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 904 times.
Similar Threads
Nested Enums
Instantiating an enum
Tiger enums....
Refactoring int constant's to use enums
Poker
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:49:17.