dimanche 28 février 2016

How to go about solving this (Design patterns)

I have a billing system in which different type of customers have different type of discount schemes. And for a given bill, a net payable amount should be generated based on the type of the customer and the product.

And there are few rules too. Like :

•If the user is an employee of the store, he gets a 30% discount

•If the user is an affiliate of the store, he gets a 10% discount

•If the user has been a customer for over 2 years, he gets a 5% discount.

•For every $100 on the bill, there would be a $ 5 discount (e.g. for $ 990, you get $ 45 as a discount).

•The percentage based discounts do not apply on groceries ...

I had few Ideas in my mind. 1st bet is to think about a decorator pattern :

Customer <<Interface>>     

|                       
CustomerImpl  



DiscountDecorator <<AbstractClass>> imp Customer

 |             |            |           |
AffiDiscount   StoreEmp   OverTwoYears   AnyOtherDisc
               Discount     Discount       Discount
Items  { 
//? ? :/
}

But then the Discounts are dependent on Items as well.

What are my options?

  • extend Customer Interface with an Item Interface to keep track on type of item?
  • Pass List of Items to the discount classes. ... How to properly have co-relation with Customer and Item classes so that I can decorate them together?

Aucun commentaire:

Enregistrer un commentaire