Aspect-Oriented Programming: An Overview Brandon Wirick Feb. 2005
Layers of Abstraction Machine code to assembly Assembly to procedural languages Procedural to object-oriented Group similar compile-time functional units Object- to aspect-oriented Group similar run-time functional units
Terminology AOP AOSD Concerns common crosscutting Aspect AspectJ Join-point Poincut Weaving compile-time run-time Loop fusion Tangling
AspectJ Java with aspects Aspects are singleton classes Group join-points into pointcuts Define behavior before, after, or around pointcuts Specify contract enforcements Can contain members, like classes Definitely most prominent language
AspectJ Example public aspect NoNulls { public static interface Addable { public boolean add(Object o); } pointcut add(Object o) : call(boolean Addable.add(Object)) && args(o); boolean around(Object o) : add(o){ boolean success = (o != null); success &= proceed(o); return success; } class NoNullsVector extends Vector implements NoNulls.Addable {} class NoNullsArrayList extends ArrayList implements NoNulls.Addable {}
Kiczales et al, 1997 Noted certain problems could have implementations that are either Efficient, but hard to understand Inefficient, but easy to understand Efficient and easy to understand, but only with AOP! “Reduction in bloat due to tangling”
Design Pattern Libraries public abstract aspect ObserverProtocol { protected interface Subject {} protected interface Observer {}... protected abstract pointcut subjectChange(Subject s);... public aspect ColorObserver extends ObserverProtocol{ declare parents: Point implements Subject; declare parents: Screen implements Observer;...
Not for Dumb Programmers Easy to do wrong Complicated to understand Controversial Not so much anymore Arguments against AOP pretty weak Some unpredictable behavior?