|
I’ve started Dave Thomas’ series of programming Kata. 1. does fractional money exist? nope. Just integers expressing the smallest monetary unit, e.g. pennies. There may also be a currency indicator in the case of international interest. 2. when (if ever) does rounding take place? rounding happens according to the rules of integer truncation when RationalPrice items are bought. That is, the price is rounded towards 0. For other cases there is no rounding as it is just addition or subtraction of integers. 3. how do you keep an audit trail of pricing decisions (and do you need to)? Yes, you need to. And an audit of money changes. These should both be implemented at a low logical level. In rails I would recomend the model have some support here. I would use Log file messages to store all pricing adjustments including username of adjuster, time, and new price. Same for all monetary balance adjustments. 4. are costs and prices the same class of thing? In my mental model, they are. However prices are set by fiat by the vender whereas costs are set by those vendors I buy from. Therefore, if we are all using the same system, costs and prices are the same type of thing but under different authorities. In my model, Price is a base class. From Price we derive several subclasses: RationalPrice (x Units of Product y for Z money), DiscreteTablePrice (lookup table of prices and units, for implementing buy x get y free type stuff), SimplePrice ( facade over RationalPrice to allow for default of 1 unit), and so on. All of these provide a method buy that takes an integer quantity and a BuyableUnit and return a price for the transaction along with any extra decorator benefits like free warranty or whatever or nil if it is not possible to buy this item in that quantity or unit. Then elsewhere there must be some sort of uniform buy strategy that takes a large quantity, like 100 cans, and accesses a DiscreteTablePrice holding the buy 2 get 1 free offer. It sees it can buy 1 can for 1 dollar, 2 cans for 2 dollars, or 3 cans for 2 dollars, determines that the best unit price is had with the promotional option, and takes it over and over up to 99 cans then just simply buys one at the end. This can all be done as a simple integer partitioning problem regardless of the “real” underlying units. The pound example shows that we need a BuyableUnit class that will support the weights and measures necessary. This is probably worth not rewriting but just copying. 5. if a shelf of 100 cans is priced using “buy two, get one free”, how do you value the stock? As 33 pairs plus one can = 33 * 3 + 1 cans = 100 cans for the price of 67 cans. This value can be arrived at by using a simple greedy strategy. |
SearchUseful StuffArticle Calendar
|
|||||||||||||||||||||||||||||||||||||||||||||||||||