Hey!
I've developed an e-commerce application, and now I'm adding support for coupons and discounts. I want your opinions on this one though, since it's trickier than I first expected.
Where should I keep my logic for all different kinds of coupons?
Say I have a coupon code giving me the offer "Buy 3 and get the cheapest for free" along with another coupon "Get 20% discount on [this product]", and a bunch of other coupons ("Get 10% off total amount", "Buy 2 get 50% off the second one" and so on).
I'm thinking in the lines of having an Coupon
interface and different implementations stored in different classes, and then store the class name in the DB along with data for the coupon. This approach is the easiest to implement, but it's not very pretty to store a class name in the database...
How would you solve it? How has it been solved in earlier applications?