LoginSignup
5
5

More than 5 years have passed since last update.

実行状況に応じた横断的構造を、AspectJにより分離する

Posted at

翻訳元サイト

Production Aspect Chapter 1. Getting Started with AspectJ

キーワード

  • context passing 実行状況
  • croscutting structure 横断的構造

本文概要

実行時の状況に応じた横断的構造は、Javaのプログラムが複雑化する重要な原因のソースコードになるでしょう。

AspectJでは、このような実行時状況の性質をモジュール化する方法で実装できます。

以下のColorControl.ajではafter adviceが、FigureクラスのファクトリメソッドがColorControllingClientクラスのメソッド上より呼び出された際に実行されるようになっています。

ColorControl.aj
pointcut ColorControl {

    pointcut CCClientCflow(ColorControllingClient client):
        cflow(call(* *(..)) && target(client));

   pointcut make(): call(FigureElement Figure.make*(..));

   after(ColorControllingClient c) returning (FigureElement fe):
       make() && CCClientCflow(c){
           fe.setColor(c.colorFor(fe));
       }  
}

このアスペクトが影響を及ぼすのは少ない数のメソッドのみになりますが、AOPを用いないでこの機能を実装した場合より多くのメソッドの編集が必要になると思われます。特に、クライアントからファクトリメソッドへの制御フロー内のすべてのメソッドが編集対象になるでしょう。

参考資料

ContextPassing.png

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5