About this question
in the project I am currently working on we had three different types of prices depending on the age of the user (adult, child, etc...). So we had on the DB a table looking like this:
PRICES
type Amount
A 20
B 15
C ..
D ..
At first we only had 4 different types of prices, so in the code, we had something like this:
Map prices = new HashMap(); Where the keys were the price type.
Recently, they added a new business rule that adds 3 subtypes to every price type, so now we have something like this:
PRICES
type subtype Amount
A 1 20
A 2 15
A 3 ..
B 1 ..
B 2 ..
... .. ..
Which of the following two options do you think is better and why?
Nested Maps
Map> prices; where the keys are the price type and subtype:
prices.get(type).get(subtype);
Combined Keys
The same map than originally:
Map prices; And concatenate the keys to index the different prices:
prices.get(type+"_"+subtype);