I need to write a data structure that can return a different Price for an Item, based on the day of the week and the hour of the day. Is there a clever way to store this? I can’t think of where to start for something like this, other than maybe using a dictionary and using some kind of structured key format to indicating pricing for different time periods.
Share
Item object has a number of Price objects.
When Item is asked for price it loops through it’s Price object’s and asks each one if they are currently valid to give a price value back.
Each Price object checks against current day/time to see if his value is valid.
Hopefully you will only get one value back but if there are multiple or no matches you need some logic to go from there.