I am trying to make a Retail Store program, just for practice. It consists of a simple window with an editable JTable, showing the existing items for sell, along with its properties (price, stock, name, etc.) I would like these properties to be fully customizable (add or remove any), so the way I thought of it was to make an "Item" class which holds a list of "Property" objects. In the "Property" class I wrote two variables as follows
String name;
Float value;
The problem I have is, what if a property is a non numeric value? Such as the name of a product for example. I have thought of possible solutions to this but I am not convinced with them, so I would like to hear what would you do instead or what would be the best option in terms of good programming practices.
So far I've come up with these ideas:
- Use a String type: but this wouldn't let me operate with the value as numbers, which I may need for prices (although I know I can sort out this using parseFloat() or similar but it doesn't seem optimal)
- Use an Object type: with this I would need to store somewhere which type the value is, to cast it later, I could use an Enum type to do it, but also casting every time looks a bit like hard coding, I don't think is a good idea either