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

}

时间: 2024-08-27 04:07:39

scala 15 多重继承 AOP实现的相关文章

Desugar Scala(15) -- unapply和unapplySeq方法

欢迎关注我的新博客地址:http://cuipengfei.me/ 实在想不到什么动词可以当做脱衣服来讲了,所以从现在开始这系列博文就叫做Desugar Scala了.除非哪天才思泉涌,又想到了新词:) 开始正文. 名字叫做unapply和unapplySeq的方法在Scala里也是有特殊含义的. 我们前面说过case class在做pattern match时很好用,而除case class之外,有unapply或unapplySeq方法的对象在pattern match时也有很好的应用场景.

[Scala基础系列 08]Scala继承、抽象类、接口trait以及AOP实现

1.继承 和java一样,scala采用extends关键字继承基类.代码实例如下: /** * Created by molyeo on 2015/8/11. */ class Person(val name: String, var age: Int) { println("The primary constructor of Person") val school = "BJU" def sleep = "8 hours" override

Scala 具体的并行集合库【翻译】

原文地址 本文内容 并行数组(Parallel Array) 并行向量(Parallel Vector) 并行范围(Parallel Range) 并行哈希表(Parallel Hash Tables) 并行散列 Tries(Parallel Hash Tries) 并行并发 Tries(Parallel Concurrent Tries) 参考资料 并行数组(Parallel Array) 一个 ParArray 序列包含线性.连续的元素数组.这意味着,通过修改底层数组,可以高效地访问和修改元

AOP中的ASPECTJ

一.准备 1.架包 2.配置文件 二.注解的形式 UserDao.java 1 package cn.itcast.spring.aspectj.annocation; 2 3 public class UserDao { 4 5 public void add(){ 6 System.out.println("add......"); 7 } 8 9 public void delete(){ 10 System.out.println("delete......"

Spring面向切面编程(AOP)

1 spring容器中bean特性 Spring容器的javabean对象默认是单例的. 通过在xml文件中,配置可以使用某些对象为多列. Spring容器中的javabean对象默认是立即加载(立即实例化:spring加载完成,立即创建对象) scope:属性 singleton:默认值为单例,默认也是立即加载,在加载完成spring容器的时候,bean对象已经创建完成 prototype:多例的,默认懒加载,spring容器加载完成的时候,不会创建bean的对象,只有从容器获得bean对象的

Scala之Map,Tuple

/** * 1,默认情况下Map构造的是不可变的集合,里面的内容不可修改,一旦修改就变成新的Map,原有的Map内容保持不变: * 2,Map的实例是调用工厂方法模式apply来构造Map实例,而需要主要的是Map是接口,在apply中使用了具体的实现: * 3,如果想直接new出Map实例,则需要使用HashMap等具体的Map子类: * 4,查询一个Map中的的值一定是采用getOrElse的语法的,一方面是在key不存的情况下不报告异常,另外还有一个神奇的作用就是提供默认值 * 而关于默认

Spring AOP报错

八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org[email protected]277050dc: startup date [Mon Aug 01 22:08:48 CST 2016]; root of context hierarchy 八月 01, 2016 10:08:48 下午 org.

spring中的AOP 以及各种通知

理解了前面动态代理对象的原理之后,其实还是有很多不足之处,因为如果在项目中有20多个类,每个类有100多个方法都需要判断是不是要开事务,那么方法调用那里会相当麻烦. spring中的AOP很好地解决了这个问题,通过 execution表达式 指定哪些包中的那些类 哪些方法 用到事务 execution(public * *(..))  所有的公共方法 execution(* set*(..))  以set开头的任意方法 execution(* com.xyz.service.AccountSer

在Windows下MyEclipse运行JAVA程序连接HBASE读取数据出错

运行环境:Hadoop-2.5.0+Hbase-0.98.6 问题描述: 15/06/11 15:35:50 ERROR Shell: Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.     at org.apache.hadoop