Scala 深入浅出实战经典 第57讲:Scala中Dependency Injection实战详解

王家林亲授《DT大数据梦工厂》大数据实战视频 Scala 深入浅出实战经典(1-87讲)完整视频、PPT、代码下载:
百度云盘:http://pan.baidu.com/s/1c0noOt6
腾讯微云:http://url.cn/TnGbdC
360云盘:http://yunpan.cn/cQ4c2UALDjSKy 访问密码 45e2
土豆:http://www.tudou.com/programs/view/5LnLNDBKvi8/
优酷:http://v.youku.com/v_show/id_XMTI4NzM2OTkzMg==.html?from=s1.8-1-1.2
爱奇艺:http://www.iqiyi.com/w_19rrt84uth.html#vfrm=2-3-0-1
腾讯视频:http://v.qq.com/boke/page/x/0/2/x0159h4oa22.html
技术爱好者尤其是大数据爱好者 可以加DT大数据梦工厂的qq群

DT大数据梦工厂① :462923555
DT大数据梦工厂②:437123764
DT大数据梦工厂③ :418110145

微信公众账号: DT_Spark
王家林老师微信号: 18610086859
王家林老师QQ: 1740415547
王家林老师邮箱: 18610086859@126.com

本视频由王家林老师, 亲自讲解, 完全通过代码实战把您带人大数据的时代.

package com.parllay.scala.type_parameterizitor

/**
* Created by richard on 15-8-13.
* 第57讲:Scala中Dependency Injection实战详解
*/

trait Logger { def log (msg:String)}
trait Auth {
auth : Logger => //this别名, 在这里没有使用this, 而使用了auth, 可以使用除了this以外的名字
def act( msg : String ): Unit = {
auth.log(msg) //同样后边的log也不需要手动增加前缀 auth.log(msg),会被识别为auth.log(msg)。
}
}

/**
* DI在继承Auth的时候必须实现trait Logger. 这里必须有 with Logger,否则报 Main.type 不符合 Auth's selftype Auth with Logger
*/
object DI extends Auth with Logger {
override def log( msg : String ) = println(msg)
}

object Dependency_Injection {

def main(args: Array[String]) {

DI.act("I hope you'll like it")

}

}

  

posted @ 2015-08-15 20:27  曹振华  阅读(353)  评论(0编辑  收藏  举报