This post originated from an RSS feed registered with Java Buzz
by Thomas Gideon.
Original Post: AOP Amok
Feed Title: Command Line Interface
Feed URL: http://www.gideonfamily.org/roller/rss/cmdln?catname=Java
Feed Description: The blog of a programmer-hacktivist-curmudgeon who occasional rants about society, work, and technology, among other things. Now how do I get to a command prompt on this thing?
Is it just me or does this example seem incredibly forced? To start with, although I know this isn't the code about which the questions are being asked, why does the Content object require these "atoms" for it's properties? Mebbe I'm missing something, but when I see getName() (and hasName really is just getName in disguise), it immediately implies there is a private access name variable encapsulated in the class and the only relevant pattern at play here is retrieval of it's value. Mebbe this is bad naming, but the hasText and hasHtmlText seem to be to be even worse. What's wrong with polymorphism, here? How are you supposed to test this outside of the live container? How do you do static analysis on this code? What prevents some empty class from having so many introductions and advices that it's unmanageable?
As for the question itself, while I am not so sure about using ThreadLocal variables as Jon Lipsky suggests, I agree with his approach of abstracting away via a SecurityContext and hiding some system-level interaction with the container. Why re-invent the wheel? Carlos admits he's using WebWork, isn't he using a container that offers some security management service already? If not, why not? If there's a valid reason, what's the harm in making securable objects implement a Securable interface that AOP advice implementations can use to get the authentication token, via some of the suggestions in the article's comments, and meeting the AOP injection halfway?
Is this just using AOP to being using AOP? How does this make the code simpler and easier to understand? That is why we are all using the tools and techniques we use, right? To help tame the complexity inherent in software development? Don't mistake me, although I have yet to use it, I have sufficiently read up on AOP to understand what it is and does. I could be wrong, but Carlos' circumstances don't seem to indicate that AOP is the way to go, here; at least not for everything he seems to be using it for.