I am trying to design an promo code engine which will validate the promocode and applies discount depending on the items in the cart, promocode and User.
I was thinking that the I can have many strategies for the promocode say,
NewUserPromocodeStrategy checks the user is performing the transaction for first time. If yes then provide discount 10% discount FreqUserPromocodeStrategy checks the user is freq user and if the cart value is more than a certain value provide 5% discount
And I will have a Strategy factory for which will provide me the respective strategy class.
So I can have business logic now to calculate the discount depending on the cart, user and Strategy object I got from the factory.
Strategy st = StrategyFactory.get("NEWUSER")
if (st == null)
invalid promo code
else
calculateDiscount(user,cart,st)
Is this a good design ?
Aucun commentaire:
Enregistrer un commentaire