Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I do Aspect Oriented Programming in Scala?

Tags:

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 ...)

like image 867
Ashkan Kh. Nazary Avatar asked Feb 17 '11 06:02

Ashkan Kh. Nazary


People also ask

Is aspect oriented programming still used?

Nowadays I see some AOP still around, but it seems to have faded into the background. Even Gregor Kiczales (inventor of AOP) called it a 15% solution. So I guess AOP has its reason for existence, but it depends on the individual developer to use it the right way.

Is Python aspect oriented?

Python does not need something like a "language extension" for being able to work in an Aspect Oriented way. That is simply due to the dynamic mechanisms in Python itself. A Google search will yield a couple projects - but despite looking merely like libraries, it is all that is needed in Python.

What is Aspected oriented programming?

Aspect-oriented programming (AOP) is an approach to programming that allows global properties of a program to determine how it is compiled into an executable program. AOP can be used with object-oriented programming ( OOP ). An aspect is a subprogram that is associated with a specific property of a program.

What is the difference between object oriented programming and Aspect Oriented Programming?

OOP is mainly used to organise your business logic while AOP helps to organise your non-functional things like Auditing, Logging, Transaction Management, Security etc. This way you can decouple your business logic from non-functional logic, which makes code cleaner.


1 Answers

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

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).

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.

like image 109
VonC Avatar answered Oct 12 '22 13:10

VonC