AOP Kata: Favour OO EJB 3.0: Backwards compatibility optional?
May 06

AOP Kata: Reusable Aspects

AOP, Tech Add comments

There are certain aspects that are ripe for reuse. There are various levels of reuse of course (totally generic: Log4J, company-reuse: YourCompanyLogger, etc).

A common pattern that you run into, (we use it in aTrack. Ramnivas has it in his book, etc) is that you want to apply some advice, but only to a subset of your code.

The simple way to do this is to use the template pattern:

First, define the abstract aspect which does most of the work, but leave open a scope() pointcut:

public abstract aspect PolicyEnforcement {
  abstract pointcut scope();

  pointcut printing():
    get(* System.out) || get(* System.err) ||
    call(* printStackTrace());

  declare error: scope() && printing():
    ”Our policy enforces the fact that you have to print via our logger”;

  declare warning:
    call(Exception.new()) ||
    call(RuntimeException.new()) &&
    scope():
    ”constructing exception without

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: What are the first four letters in the word British?