tags:

views:

137

answers:

3
+2  Q: 

Scala and Aspects

Scala and Aspects can be used together? Are there benefits in this case?

Thanks

+9  A: 

Scala is just like java, if you mean for example spring-like AOP I'm sure that annotations work either in scala or in java.

On the other hand, the fact that Scala has closures (and java doesn't) makes AOP less interesting.

Pablo Fernandez
Absolutely spot on. AOP is designed to hide cross-cutting concerns. This is far more practicable in Scala with higher-order functions and implicit conversions.
Synesso
+3  A: 

Fakod has some examples for AspectJ here

Real-World Scala: Managing Cross-Cutting Concerns using Mixin Composition and AOP

oluies
More to the point: http://java.dzone.com/articles/real-world-scala-managing-cros
Aaron Novstrup
+4  A: 

In fact the Scala IDE for Eclipse uses Aspects (because the JDT assumes Java):

From Scala Support in Eclipse - Monkey-patching the JDT for fun and profit?, p16 by Miles Sabin

AspectJ and Equinox Aspects

  • A collection of aspects is effectively a patch
  • AspectJ was used to retrofit the desired extensibility features to the JDT and expose them via public API
  • The key modification:
    • The JDT's CompilationUnit is the entry point to it's internal model, but it assumes Java source
    • An aspect can turn its constructor into a factory method

So the answer is Yes, it is possible. I have to agree with Pablo that it's less attractive than in Java.

MatthieuF