views:

46

answers:

1

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?

A: 

I think a Rules Engine offers a good path to model coupons in a decoupled way.

See for example THIS sample app using Drools.

HTH!

belisarius
Thank you for your reply! Altough I don't think your example are the best way to solve this - it stores pure code in XML files! I think I would prefer to store the path to an implementation in a datasource, instead of the implementation itself. The Rules Engine is probably the right approach though!
Björn