文档介绍:Scala 解决问题
精选课件
目录
Why scala
用scala 解决问题
More about scala
Q &A
Polyglot val negativeProfit: Filter = new Filter {
def apply(pricing: Pricing) = pricing match {
case SubmitPricing =>
if ( < getWarehousePrice()) {
trace("negative profit " + pricing)
new ManualPricing(, , pricing)
}
else pricing
case _ => pricing
}
}
精选课件
Function composition :2
val exceed: Filter = new Filter {
def changeCheck(a: Float, b: Float, per: Float): Boolean = (a - b) > a * per
def apply(pricing: Pricing) = pricing match {
case SubmitPricing =>
if (changeCheck(, ,
getThreholdPercentage()))
new ManualPricing(, , pricing)
else pricing
case _ => pricing
}
}
def followingRule(event: Event) =
following andThen
negativeProfit andThen
exceed
def markdownRule(event: Event) =
markdown andThen
negativeProfit andThen
exceed
精选课件
Function composition :3
abstract class Pricing(ev:Event,p:Float) {
def event:Event = ev
def price:Float = p
def process
}
case class SubmitPricing(ev:Event, p:Float,ca:String)
extends Pricing(ev,p){
val cause = ca
override def process = {
//submit to system
}
}
case class ManualPricing(ev:Event, p:Float,so:Pricing)
extends Pricing(ev,p){
val source:Pricing = so
override def process = {
//record apply
}
}
精选课件
Cake pattern ( dependency injection) :1
object Pricing extends PricingService with Tracer {
def apply(ev:Event) = {
if( isPromoted()) {
trace("promoted " + ev)
}else{
val rule = (ev)
rule(ev) process
}
}
}
精选课件
Cake pattern ( dependency injection) :2
trait PricingService {
def getOppproduc