3

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

Thanks

adelarsq
  • 3,718
  • 4
  • 37
  • 47

3 Answers3

10

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
  • 103,170
  • 56
  • 192
  • 232
  • 4
    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 Oct 15 '10 at 02:34
6

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.

Community
  • 1
  • 1
Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
3

Fakod has some examples for AspectJ here

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

Robin Green
  • 32,079
  • 16
  • 104
  • 187
oluies
  • 17,694
  • 14
  • 74
  • 117