我可以在 Scala 中进行面向方面的编程吗? [英] Can I do Aspect Oriented Programming in Scala?

查看:28
本文介绍了我可以在 Scala 中进行面向方面的编程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是在谈论在 Scala 中模仿 AOP 功能(即使用 Traits 而不是 Aspects),我想知道是否有可能在 Scala 中执行真正的 AOP(即建议、方面、联合点、编织等)..)

I'm not talking about mimicking AOP features in Scala (i.e. using Traits instead of Aspects), I'm wondering if it is possible to do true AOP in Scala (i.e. advices, aspects, joint points, weaving etc ...)

推荐答案

Mixin 一直是在 Scala 中引入 AOP 的经典方式(如Scala 中的 AOP 风格 Mixin 组合堆栈",来自 Jonas Bonér).

Mixin has been the classic way to introduce AOP in Scala (as in "AOP-style Mixin Composition Stacks in Scala" from Jonas Bonér).

但我只知道Scala 中基于方法代理的 AOP"(Daniel Spiewak -- 也在 SO 上 -- 和 Tian Zhao)作为 Scala 中的高级 AOP 实现(此处为源代码).

But I know only of "Method Proxy-Based AOP in Scala" (Daniel Spiewak -- also here on SO -- and Tian Zhao) as an advanced AOP implementation in Scala (source code here).

我们的技术使用 Scala 的高阶函数来拦截方法调用,同时对基础程序施加最小的语法开销.
该框架允许开发人员通过指定类类型和方法签名来定义切入点.该框架还允许访问上下文变量,而方面可以在建议正文之前或之后插入建议代码.

Our technique uses Scala’s higher-order functions to intercept method calls with minimal syntactic overhead imposed on the base program.
This framework allows developers to define pointcuts by specifying class types and method signatures. The framework also allows access to context variables, while aspects can insert advice code before or after the advised body.

这篇关于我可以在 Scala 中进行面向方面的编程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆