aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes design question - interface for discounts (how to?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "design question - interface for discounts (how to?)" Watch "design question - interface for discounts (how to?)" New topic
Author

design question - interface for discounts (how to?)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
can you tell me more about "rules engine"
thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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."


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: design question - interface for discounts (how to?)