• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

design question - interface for discounts (how to?)

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have a contract with restrictions and discounts that needs to be checked against a carRental.

Example:
User rent a car with the possible following properties:

1.Rent date between A and B
2.Type of car (SUV, luxury, sport)
3.location of rent

(in future can add more)

*assuming the contract speaks only about eligible discounts

The contract offers discount if the rent is in certain location (eg., rent from JFK airport) or the dates is between Jan-01 and Jan-20 etc.

My question is this: how should I design a contract where the discount can change periodically, manning a new discount will be added (eg next month the carRental will add this discount: if car is Yellow give extra 10% discount or if car is not �new� add 15% discount. )

I thought of an interface of discount and every discountClass will implement the interface but I�m not sure how to have it work in terms of contract checks for all possible restrictions/discount

Anyone?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if the Decorator pattern in this sample chapter from Head First Design Patterns sounds applicable to your problem. That lets you add modifiers to a method like getPrice().

If you really want to go wild, this is a good problem for a rules engine, too. That would be a pretty large learning curve, but might pay off if you have other places to use it.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell me more about "rules engine"
thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "rule engine" is software that lets you implement business rules in a declarative way that's easy for business folks to understand. The rules are kept separate from the applications code; they're expressed in a "rule language" which is more appropriate to the task. This makes them easier to modify and easy to track, version, and otherwise manage.

Search Amazon for "the business rules approach."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic