Annotation and Inter-type Declarations or Retroactive Abstraction
時には、あるアノテーション(@)を定義しているかどうかで、クラスの構成を自動的に決めたい場合がある。
たとえば、メソッドをアドバイスとして定義したら、そのクラスは、Aspect の interface を実装するなど:
具体的なコード例では、たとえば:
public class Logging implements Aspect {
// このアノテーションを持っていたら
// 自動的に Aspect interface を実装するようにしたい
@BeforeAdvice(pc="call( void MyClass.method() )")
public void log() {
System.out.println("before");
}
}
みたいな感じに。
public aspect AspectImplementation {
declare parents:
within(*) &&
methods() &&
hasAnnotation(BeforeAdvice) implements Aspect;
}
関連:
AspectJ では、既存のクラスに外部からスーパークラスやインタフェースを追加するような機能は、inter-type declarations と呼ばれている。
Half & Half では、Retroactive Abstraction と呼ばれているらしい(まだ読んでない)。
G. Baumgartner, M. Jansche, K. Läufer
Half & Half: Multiple Dispatch and Retroactive Abstraction for Java
Technical Report No. OSU-CISRC-5/01-TR08, Dept. of Computer and Information Science, The Ohio State University, March 2002.
DL: http://www.cse.ohio-state.edu/~gb/publications.html
MultiJava の今後は、現在の MultiJava のオープンクラス能力に加えて、AspectJ や Half & Half のように、既存のクラスに外部からスーパークラスやインタフェースを追加できるようにするらしい。
Curtis Clifton, Todd Millstein, Gary T. Leavens, and Craig Chambers.
MultiJava: Design Rationale, Compiler Implementation, and Applications.
accepted to TOPLAS.
DL: http://multijava.sourceforge.net/pubs.shtml
昔読んだ論文なのであまり覚えていないけど、ロジックな雰囲気でクラスの構成を変える提案:
Kniesel, G.; Rho, T.; Hanenberg, S
Evolvable Pattern Implementations Need Generic Aspects
Workshop on Reflection, AOP and Meta-Data for Software Evolution at ECOOP, Oslo, Norway, June 15, 2004.
DL: http://dawis.informatik.uni-essen.de/site/staff/shanenbe/
Hanenberg, S., Unland, R
Parametric Introductions
2nd International Conference on Aspect-Oriented Software Development (AOSD), Boston, MA, March 17 - 21, 2003
DL: http://dawis.informatik.uni-essen.de/site/staff/shanenbe/