Ramnivas just published the
second
part of his AOP refactoring series
and I have a quick remark on the second
second example (listings 3 and 4) where he abstracts the concurrency mechanism
in an aspect.

I agree that the business logic that takes care of the concurrency belongs in
a separate aspect, but not the pointcut definition. I think this is a very good
example where the pointcut definition should be specified inside the code, not
separately.

Determining if a method should get a read or a write lock is fundamentally
tied to the code inside the method, so I believe this should be specified on the
method itself, with an annotation. Using a separate pointcut is inherently
fragile because you have to specify the method names inside, which is
error-prone because

  • Method names can change.
     
  • Their inside logic can change (you used to need just a read-only lock
    and now you need a write lock).

Both these actions will force you to remember to modify your pointcut
definition as well. I believe that having an annotation such as

@ReadLock
public float getBalance() {
// …
}

makes it easier for the developer to maintain his code.