P - U - public abstract class AbstractChargeStrategy<P extends Product,U extends User> extends AbstractStrategy<P,U> implements CumulativeChargeStrategy<P,U>
ChargeStrategy| Modifier and Type | Field and Description |
|---|---|
protected TaxStrategy |
taxStrategy
Tax can be factored into any other Strategy, so providing by default
|
productService, scanHierarchy| Constructor and Description |
|---|
AbstractChargeStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyTax(Amount amt,
P product)
Convenience method for applying tax over individual strategies
|
<CONTEXT> Amount |
calculate(Map<P,Number> productQtyMap,
U user,
String currency,
List<PromotionForUser> promotions,
Amount subTotal,
Number quantityTotal,
CONTEXT context)
Calculate raw amount for product(s)
|
TaxStrategy |
getTaxStrategy()
Tax can be factored into any other Strategy, so providing by default
|
String |
getVersion()
Strategies change; it may be important/required in most applications to know a result based on which version of a particular strategy.
|
void |
setTaxStrategy(TaxStrategy taxStrategy)
Tax can be factored into any other Strategy, so providing by default
|
getProductService, getRepresentativeProduct, isScanHierarchy, setProductService, setScanHierarchyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcalculateprotected TaxStrategy taxStrategy
protected void applyTax(Amount amt, P product)
amt - as Amountproduct - as Ppublic <CONTEXT> Amount calculate(Map<P,Number> productQtyMap, U user, String currency, List<PromotionForUser> promotions, Amount subTotal, Number quantityTotal, CONTEXT context)
CumulativeChargeStrategycalculate in interface CumulativeChargeStrategy<P extends Product,U extends User>productQtyMap - as Map of Product to Number (Quantity)user - as U @NUllable truecurrency - as String @nullable true. A null implies default currency. Note: If not null then this will override subTotal Amount.getCurrency().subTotal - as Amount; many scenarios use the Sub-Total of products to calculate other params. So provide that as a defined context variable. @nullable truequantityTotal - as Number; many scenarios use the quantityTotal of products to calculate other params @nullable truecontext - as additional case driven params that can be supplied @nullable trueAmount.getTotal() should be positive; while Amount.getDiscount() should be negative number.
This is because a Discount is DEDUCTED. So while it makes sense to DEDUCT a positive value from TOTAL; the discount itself should be ADDED
hence = >
Existing Total - (This Discount as Total)
Existing Discount - (-This Discount) = Existing Discount + This Discountpublic TaxStrategy getTaxStrategy()
public void setTaxStrategy(TaxStrategy taxStrategy)
public String getVersion()
getVersion in interface StrategyCopyright © 2018. All rights reserved.