Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Re: RE: [aspectj-users] Any useful examples

True, I could put the defaulting code right next to the System.getProperty() call either manually or using a PropertyManager like Rudi suggested. The problem with the first option, manually putting the code there, is that what if code refactoring/rearrangement caused the property to be read before the "expected" first read? I would have to propagate the defaulting code wherever the System.getProperty() occurs - obviously a bad solution. I could use the property manager technique, but that would require writing all kinds of overhead and would add a dependency in my code to the property manager. Also, I couldn't get around the ordering problem with the property manager... I had to have my property file define the properties in the correct order for it to work right too. Tracking that down was easy since I knew it was an issue from my trial-and-error approach earlier, however, if I were another developer, I would've been lost. I can't count the times I've gotten lost in property file hell...

I will admit that the approach I used puts a compile time dependency on setting defaults. However, those default values aren't likely to change much over the lifetime of the application. The nice thing is, that if I do decide to put a property manager into place, i.e., when the number of properties to define on the command line gets too cumbersome, I can still use the aspect to do the defaulting. The property manager will call System.getProperty() and the aspect will intercept it. Using an aspect also makes the PropertyManager class more flexible -- the defaulting logic, which is almost always application specific, doesn't need to be embedded in the class. Another point to consider is what happens if a property in the property file is accidentally deleted (when only using the property manager approach)? The app is broken. By using AOP, I make required properties resilient, remove unnecessary ordering dependencies and simplify my code all without limiting future design choices.


A more advanced philosophy that's been germinating is to combine declarative programming - aspects and rules - with functional programming - POJO. What I mean by "functional" is programming that is defined by structure and sequence. I use POJO to capture state. Aspects are then used to capture state changes. Finally, the rules decide what should occur based on those state changes. I wrote a proof-of-concept app using JAXB and Swing and was able to completely remove my business logic from the Swing components! I even moved component behavior logic out of the main app. The class with the main() method simply became an object container.


-------Original Message-------
> From: Kenworthy, Edward (EDS)
> Subject: RE: [aspectj-users] Any useful examples
> Sent: 08 Aug 2003 07:04:49
>
> It's not at all clear to me how aspects help with what seemed to be your
> main problem:
>
> "if I add another property that needs a default, where do I put the call?"
>
> As if you know enough to define the point cut then surely you must know the
> answer to this in advance for all cases ?
>
> Edward

Back to the top