Skip to content

Instantly share code, notes, and snippets.

@techwhizbang
Created January 11, 2011 01:24
Show Gist options
  • Save techwhizbang/773835 to your computer and use it in GitHub Desktop.
Save techwhizbang/773835 to your computer and use it in GitHub Desktop.
override def calculate(cartItem: CartItem): DiscountResult = {
val saleDao = saleDao.findSale
if (shopKeeperSale != None) {
if (isThis(cartItem.getProductData) ||
isThat(cartItem.getProductData)) {
new DiscountResult(DiscountType.SOME_TYPE_A, percentageOff)
} else {
new DiscountResult(DiscountType.SOME_TYPE_B, percentageOff)
}
} else {
new DiscountResult(DiscountType.NONE, 0)
}
}
@techwhizbang
Copy link
Author

I went ahead and made the points of return, functions themselves, but I still feels there may be a cleaner way.

override def calculate(cartItem: CartItem): DiscountResult = {
val saleDao = saleDao.findSale

if (shopKeeperSale != None) {
  val percentageOff = shopKeeperSale.get.percentOff / 100f
  if (isThis(cartItem.getProductData) || isThat(cartItem.getProductData)) { {
    actualPriceDiscountResult(cartItem, percentageOff)
  } else {
    basePriceDiscountResult(cartItem, percentageOff)
  }
} else {
  noDiscountResult
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment