Reputation: 25
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:
Upvotes: 2
Views: 451
Reputation: 51565
Even if you limited yourself to numeric properties, price is a different type of number from weight. Adding in string properties makes it more difficult to manage just one property class.
One answer is to have more than one property class. One for strings, one for integer numbers, and one for prices. A reason to separate prices from other numbers is that you want to be careful when adding and subtracting prices.
Upvotes: 2