scala 15 多重继承 AOP实现

DT大数据梦工厂scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group

《Scala深入浅出实战初级入门经典视频课程》http://edu.51cto.com/lesson/id-66538.html

《Scala深入浅出实战中级进阶经典视频课程》http://edu.51cto.com/lesson/id-67139.html

class Test extends ConsoleLogger{
def test{
log("Here is Spark!!!")
}

}

abstract class Account{
def save
}

class MyAccount extends Account with ConsoleLogger{
def save{
log("11")
}
}

class Human{
println("Human")
}
trait TTeacher extends Human {
println("TTeacher")
def teach
}
trait PianoPlayer extends Human {
println("PianoPlayer")
def playPiano = {println("I’m playing piano. ")}
}
class PianoTeacher extends Human with TTeacher with PianoPlayer {
override def teach = {println("I’m training students. ")}
}


//AOP
trait Action {
def doAction
}
trait TBeforeAfter extends Action {
abstract override def doAction {
println("Initialization")
super.doAction
println("Destroyed")
}
}

class Work extends Action{
override def doAction = println("Working...")
}

object UseTrait extends App{
// val t1 = new PianoTeacher
// t1.playPiano
// t1.teach
// val t2 = new Human with TTeacher with PianoPlayer {
// def teach = {println("I'm teaching students.")} }
// t2.playPiano
// t2 teach
val work = new Work with TBeforeAfter
work.doAction
// val logger = new ConcreteLogger with TraitLogger
//// val logger = new ConcreteLogger
// logger.concreteLog
// val logger = new Test
// logger.test;
//
// val account = new MyAccount with TraitLoggered
// account.save


}

posted on 2015-08-30 12:00  trgaaaaa  阅读(381)  评论(0编辑  收藏  举报