views:

35

answers:

1

I have this domain model (simplified), that represents a product that has a basic price and attached has numerous suppliers that provide a specific discount percentage against the basic price:

public class CarDerivative
{
    public string Name { get; set; } e.g. StackOverflow Supercar 3.0L Petrol
    public double BasicPrice { get; set; } e.g. 10,000
    public double Delivery { get; set; } e.g. 500
    public IList<SupplierDiscount> { get; set; } // has 3 various suppliers
}

public class SupplierDiscount
{
    public string SupplierName; { get; set; }
    //public SupplierInformation SupplierDetails { get; set; } // maybe later
    public double BasicDiscount { get; set; } 
    public double DeliveryDiscount { get; set; } // e.g. 0.10 = 10%
}

Now, I'm thinking about where stuff should sit that does stuff with this:

For example, where best does BasicDiscountedPrice (stable formula) sit, should it ideally sit on SupplierDiscount which is furnished with a reference to the parent CarDerivative via constructor injection?

Where in your opinion should an unstable formula sit? Such as SupplierPriceForDerivative (basic + delivery + tax +++) ?

A: 

My knee-jerk reaction to this would be that Discounts should be Policies. Each DiscountPolicy might look like this:

public interface IDiscountPolicy
{
    decimal GetDiscountedPrice(CarDerivative car);
}

Your SupplierDiscount might be a simple implementation of such a Policy, while your unstable formulas might be implemented in a more complex class.

I think it would be safest to keep the Entities and the Policies separate, so that you can vary them independently from each other.

Mark Seemann