In general, the approach makes sense to me. Having been down this route before (just not with OO languages to support me), there are some business issues to consider.
ajj3085:Hi,
Now, I don't intend on having the class look at a particular customer and figure it out itself; instead, I want to give the users a way to switch a flag that affects its behavior.
Here's an example:
I negotiate a special deal with management, that my minimum shipping fee is $5 instead of the normal $10. We put it into our contract.
You implement this as an option that the user chooses from when filling out the line item.
All the sales staff are told about the exception via an email memo or staff meeting.
A new guy joins the sales team and, of course, no one sends him last months email or remembers to tell them about the special rule for this customer.
He invoices them $10 instead of $5 for shipping on several orders.
Another clerk is "less than average in reliability". This might be because he's depressed, or hung-over, or just doesn't give a rat's behind about the quality of his work. So, in a boredom-induced stupor, he enters "the usual" $10 shipping fee for several more orders.
The customer notices that they are being charged $10 instead of $5 despite a contract to the contrary.
The important question is:
How mad will the customer get and how much money might it cost the company in lost sales?
So, you might want to consider adding the ability to set a non-default choice at the customer level for these types of customizations.
You could also implement a strategy pattern. ie. Define an interface such as IPackingFeeCalculator or maybe ILineItemTotalCalculator which would have a Calculate method of some kind. Then you create various implementations of the calculator such as PercentageOfQuoteTotalCalculator or MinimumFeeCalculator. Use some sort of "dependancy injection" to give the LineItem class the appropriate implementation either through the constructor or by setting a property. Or you could create as needed in the LineItem class (less testable).
One side effect of this is improved testability since you would be able to mock the ILineItemTotalCalculator and thus test isolated behavior of the LineItem class without worrying about possible bugs with the calculator classes.
Copyright (c) Marimer LLC