These prices and discounts are DATA! Data should never be compiled into code
I wouldn’t collect drops in the code, Id builds the basic pricing structure (they can play well with falling prices, but they are less likely to change the overall pricing structure).
I have prices and discounts in an easily changeable place (for example, database, xml file) that reflects this structure.
public class Pricing { private List<Tuple<decimal, decimal>> pricePoints= new List<Tuple<int, decimal>> discountRanges(); public Pricing() {
If you create drops in the code and they change drops, you must change the code.
Put the data in a file, upload the file once at runtime, and they can change prices, and you just need to change the file.
Return to comment "This is obviously a business rule."
Excluding discounts at the point of sale (2 for one offer, 10% of this product, etc.), there are three ways to calculate the discount on the total fee or fee (any of which can be combined with the preferred discount for customers).
- Flat percentage (e.g. 10% always)
- Different percentages for different price points.
- Different flat prices for different price points (this is what we see in the question)
Which of them (or those) that the client decides to use is a business rule and yes, the rule must be presented in code.
However, no matter which rule is used, the actual values are data, and should never be in the code (except in exceptional circumstances).
source share