0

I'm working on the promotion part of an ecommerce website.

We have two kinds of promotions:

  1. Offer discount to customers
  2. Offer gift products (free) to customers

Both promotions require some preconditions to be met by customers. For example, if the subtotal of the shopping cart is over $1000, the customer can get 20% discount. Another example, if the subtotal of the shopping cart is over $1500, the customer can get an iPad 3 as gift.

You can see that, the preconditions of these two promotion are similar. So I use a Promotion class to represent a promotion, and a PromotionRule class to present a precondition that customers should meet. The the models are (written in C#):

public class Promotion {
    public string Name { get; set; }
    public PromotionType Type { get; set; }
    public decimal DiscountAmount { get; set; }
    public IList<Product> GiftProducts { get; set; }
    public IList<PromotionRule> Rules { get; set; }
}

public enum PromotionType {
    Discount = 0,
    GiftProduct = 1
}

public class PromotionRule {
    public decimal? MinAmountOfTheShoppingCart { get; set; }
    ...
}

You can see that, a promotion can have a list of promotion rules which should be met by customers. The PromotionType is used to indicate whether we will offer customers discounts or gift products.

Now, my question is: Is PromotionRule a good name in this case? Because I'm not very good at English. I don't know if this name is easy to understand. Thanks!

Mouhong Lin
  • 4,402
  • 4
  • 33
  • 48

1 Answers1

1

...a PromotionRule class to present a precondition that customers should meet.

I don't think "rule" is a bad name. A rule usually contains one or more implicit or explicit conditions.

Wikipedia lists a few examples under business rules:

For example a business rule might state that no credit check is to be performed on return customers. Other examples of business rules include requiring a rental agent to disallow a rental tenant if their credit rating is too low, or requiring company agents to use a list of preferred suppliers and supply schedules.

In the first Wikipedia example, we see the condition:

if( !isReturnCustomer ){
    PerformCreditCheck();
}

A rule can easily have more than one condition, e.g.:

if( temperature < 0 && isRaining ){
    HandleFreezingRain();
}

Therefore, I suggest "rule" if your class encapsulates multiple conditions, or "PromotionCondition" if the object encapsulates only a single condition. Or perhaps a PromotionRule class which contains a collection of PromotionConditions.

Tim M.
  • 53,671
  • 14
  • 120
  • 163