scala 15 多重继承 AOP实现

本文分享了Scala的学习资源,包括视频教程链接及代码示例。涵盖了Scala的基础语法、面向对象编程特性以及如何结合特质使用等内容。

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


}

转载于:https://www.cnblogs.com/trgaaaaa/p/4770621.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值