Simplifying Pointcut Definitions
AspectJ におけるポイントカットの定義を、もっとシンプルにできるか?
一つの方法は、もし、あるアスペクトが特定のクラス(or アスペクト)にしか興味がないのであれば、クラスの指定を省くことで、ポイントカットの定義をもっとシンプルに書ける。
たとえば
というクラスがあって、アスペクトがこのクラスにしか興味がないのだとすると:
public class MyClass {
public void method1() { ... }
public void method2() { ... }
}
と書くよりも、例えば(したがって AspectJ ではコンパイルできないけれども):
public aspect MyAspect {
before() : call(void MyClass.method1() ) { ... }
before() : call(void MyClass.method2() ) { ... }
}
と書ければシンプルになる 気が する。
public aspect MyAspect{
before() : call( void method1() ) { ... }
before() : call( void method2() ) { ... }
}
AspectName<ClassName> としているのは単に他の指定の方法を思い浮かばなかっただけで、これが良い表し方だ、というわけではない。
インスピレーション元:
Miguel Pessoa Monteiro and Jo縊 M. Fernandes
Object-to-Aspect Refactorings For Feature Extraction
3rd International Conference on Aspect-Oriented Software Development (AOSD 2004),
DL: http://www.di.uminho.pt/~jmf/PUBLI/publica.html
のコード読んでたら思いついた。