AOP in Practice:
Object Cache Implementation
Aspect-Oriented Programming (AOP) is making its way from the research labs to real-world usage. While the concepts are clearly defined, and even a range of AOP tools is now available, use cases from the real world are still scarce. “Implementing Object Caching with AOP” is an article from Srini Penchikala that highlights a detailed and practical example for the realistic usage of AOP.
Srini Penchikala, Information Systems Subject Matter Expert at Flagstar Bank, has already published a range of articles and is well known in the J2EE area. On the Java community Web site “TheServerSide.com” he presents a demonstrative and practical example for the beneficial usage of AOP techniques. The tools used are AspectJ, JBossCache and OSCache, but even so the article tries to stick to a neutral, not tool-bound presentation of the concepts. AOP programming experience of the reader is not presumed.
The published example consists of an implementation of an object cache for a J2EE application. After motivating to recognize and to define such an object cache as an aspect, Penchikala outlines in detail the caching functionalities to be implemented. The implementation of cache accesses using AspectJ is explained extensively, supported by test results. An AOP appendix illustrating the most important AOP terms closes the article.
"One advantage of using aspects compared to traditional object oriented programming is that if something doesn't turn out to be as effective as originally expected, the aspect can be seamlessly un-weaved from the application code without any impact on the actual code. Aspects provide plug-n-play capabilities in the application development."
(S. Penchikala, in the article “Implementing Object Caching with AOP”)
Classical approaches to implement a cache consist of the implementation of the access logic within its own class, states Penchikala. This is completed by the encapsulation of cache accesses in specific methods for each class, or by a method inherited from a common base class. Here, AOP provides the advantage of a clean, seamless separation of caching from pure application logic. The caching could be enabled or disabled at will, and one could switch between different caching techniques without producing any maintenance or runtime overhead.
Penchikala demonstrates the advantages of the aspect-oriented implementation by presenting test results taken with caching enabled and disabled. A direct comparison of the AOP implementation with a classical OO implementation, however, is not presented. Conceptually, the advantages of the AOP solution are clear. Nevertheless, it would be interesting to quantify the reduction of overhead – and therefore the value of the AOP implementation. But, as always please read the article and form your own opinion.
You will find Srini Penchikala’s article at:
http://www.theserverside.com/articles/article.tss?l=ObjectCachingWithAOP




