The example on the ColdSpring site shows how AOP can be applied to handle logging across an application, but that doesn't seem all that useful (or sexy) to me. I wanted a better scenario.
After reviewing some code in a project I've been working on, I noticed a prime example of where I could use AOP: caching.
There was code inside multiple function calls that would perform caching based on the component, method, and arguments being passed into the method. The code was using non-deterministic caching, meaning if the data didn't exist in the cache, the system would fetch the data then put it into the cache. The caching code looks similar to this:
<cfset key = application.cache.getKey("reportDAO","getReportByID",arguments) />
<cfset report = application.cache.getData(key) />
... build the report ...
<cfset application.cache.setData(key,report) />
The code worked fine, but I had to add those same 4 lines of code to each method I wanted to cache. Plus, it led to a low level of cohesion; the method needed to know how to build a report as well as how to store and retrieve itself in memory.
With AOP, I could now configure ColdSpring to intercept each method call I wanted to cache without having to flood my code with caching logic.
As a nice side bonus, the non-deterministic key/value caching strategy I was using turned out to be similar to how memcached, a high-performance, distributed memory object caching system, caches its data. Knowing this, I was able to modify the caching advice component I created and plugin memcached in a matter of minutes.
I'm currently working on an XML based caching component that will handle bean/method caching in the request scope, session scope, and memcached. I'll post more details when I have something to show.