码迷,mamicode.com
首页 > 其他好文 > 详细

scala 15 多重继承 AOP实现

时间:2015-08-30 12:34:49      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

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


}

scala 15 多重继承 AOP实现

标签:

原文地址:http://www.cnblogs.com/trgaaaaa/p/4770621.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!