1 / 13
文档名称:

Scala解决问题.pptx

格式:pptx   大小:482KB   页数:13页
下载后只包含 1 个 PPTX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

Scala解决问题.pptx

上传人:wz_198613 2018/8/4 文件大小:482 KB

下载得到文件列表

Scala解决问题.pptx

相关文档

文档介绍

文档介绍:Scala 解决问题
目录
Why scala
用scala 解决问题
More about scala
Q &A
Polyglot programming
Polyglot programming
Java
Scala
Ruby
Python
Groovy
C++
……
Why scala
Productivity
Maintainability
extensibility
High order function
class FollowingRule() extends Rule with PricingService {
def apply(ev: Event):Pricing = {
val oppProducts: List[OppProduct] = getOppproducts()
val availabled = oppProducts filter { } //有货的
availabled match {
case List() => new AbnormalPricing(ev, "without opponent")
case _ => {
val lowPriced: OppProduct = () //最低价的
new SubmitPricing(ev, , "following " + lowPriced)
}
}
}
}
position :1
object RuleFactory extends PricingService with Tracer{
abstract class Filter extends (Pricing => Pricing)
val following = new FollowingRule()
val markdown = new MarkdownRule()
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
}
}
position :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
position :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 proc