インタープリタパターンの特徴:複雑な処理の隠蔽
処理部品の中で処理部品を構造的に宣言したり、処理部品を生成する静的メソッドを定義することにより構造を隠蔽することが可能。
LISPにおけるマクロとはS式を生成するS式(http://www.geocities.jp/m_hiroi/xyzzy_lisp/abclisp08.html)であるが、 インタープリタパターンにおけるLISPマクロに対応する実態は、コンストラクタツリーを生成する処理自体である。 具体例を以下に示す。

例:オブジェクトを変換するためのパッケージwoolpack.el.convertにおける単純型変換器を返す静的メソッド
public final class ConvertConstants {
  public static Convertable getSimpleConverter(
      final NumberFormat numberFormat, final DateFormat dateFormat,
      final BooleanFormat booleanFormat) {
    return new DelegationIfNecessityConverter(new ToTypeToWapperConverter(
        new SimpleConverter(numberFormat, dateFormat, booleanFormat)));
  }
  // ...
}


例:EL(expression language)パッケージwoolpack.elにおけるドット区切りのプロパティ名一覧の順に基点をたどっていくEL実装のコンストラクタ
public class PathEL extends AbstractEL {
  private final EL el;
  public PathEL(final String expression, final PropertyELFactory factory) {
    super();
    final StringTokenizer st = new StringTokenizer(expression, ".");
    final Collection<EL> c = new ArrayList<EL>();
    while (st.hasMoreTokens()) {
      c.add(new PropertyEL(st.nextToken(), factory));
    }
    el = new ArrayPathEL(c);
  }
  // ...
}
トップに戻る
Copyright (C) 2006 Takahiro Nakamura. All rights reserved.