Dependency Injection with AspectJ and Spring
An anonymous reader writes "IBM DeveloperWorks has an interesting article about the complementary aspects of dependency injection and aspect-oriented programming. Adrian Colyer, Chief scientist of Interface21, examines how to combine these two techniques to 'facilitate advanced dependency injection scenarios.' From the article: 'Dependency injection and aspect-oriented programming (AOP) are two key technologies that help to simplify and purify domain models and application layers in enterprise applications. Dependency injection encapsulates the details of resource and collaborator discovery, and aspects can (among other things) encapsulate the details of middleware service invocations'"
Who wrote that? The Marketing Department?
Well you sir are a fastishio, see I can make up words too.
This is good news! I have long wanted to "encapsulate the details of middleware service invocations".
Did you understand the summary? Or do you just post anything with a lot of buzzwords in it?
Donald 'Duck' Dunn: We had a band powerful enough to turn goat piss into gasoline.
Finally, with more articles like this I can say that reading Slashdot is actually good for my thesis on AOP.
I'd rather use RoR or any other dynamic language for web dev in general. However, there are still many business requirements that can come up (OLAP for one - Mondrian) that keep me coming back to j2ee for now.
The Spring framework reduces IoC and AOP to configuration details (XML - blech) so you don't have to worry to much about the implementation. Very powerful I'm sure in the hands of a seasoned Spring user.
Aside from more jargonism, can anyone cite one major application, one major project for which this was used?
I'm signing up for my 10-year training plan to learn the terminology, jargon, etc.
Then I'll consider if I even want to learn to apply it. Sheesh, this is embarrassing
"Rod Johnson"? Sounds like the name of a new adult film star.
----- If communism is a system where the government owns business, what do you call a system where business owns govern
To summarize Fowler's summary:
It's a complicated way of getting around some problems caused by Java; problems which don't occur in dynamic languages such as Ruby.
GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
OK, I think that it's fair to say that AOP is still very much at the cutting edge of developement in the java community.
Essentially the idea with AOP is that you increase the modularity and decrease the coupling of components in your application. An example of this would be Logging.
Now most (if not all) apps need to have logging code of one sort or another. This means that the code necessary to log to whichever system (commons-logging, log4j etc in the java world) you use tends to touch all of the classes/objects in your application.
Consider a situation where you have a large existing code base that you have refactored using well understood techniques such as extract method and extract superclass until you have a wonderfully clean and consistent application. You will find that even after this refactoring you still have dependencies throughout your code on your logging mechanism that cannot easily be refactored away.
In software engineering terminology this means that your application code is tightly coupled to whichever logging implementation it uses. This is a bad thing. It makes the application brittle - caveat, see 1 below.
Aspect Orientated Programming can help solve these sorts of problem by introducing another conceptual level into traditional OO. You can move the common logging code into one or more Aspects. These are separate from the rest of your codebase. When the application is run, the aspects are used to modify the code in your application to, for example, use your preferred logging implementation - oh, and before someone flames me saying I'm wrong, I know that with java this isn't exactly how it works, but it's a useful lie!
Now the interesting thing about Spring is that it's one of the first widely accepted uses of AOP. I know that even a year ago AOP was mainly of interest to comp-sci academics and bleeding-edge technologists but with Spring incorporating it into the framework it has brought AOP to a lot of people's attention.
Inversion of control, otherwise known as the Hollywood Principle (don't call us, we'll call you), refers to the currently accepted/hyped practice of "telling things what to do" rather than "things inherently knowing what to do". It's obviously a lot more complex than that, and a lot has been written about the technique but that's the basic gist.
As for citing major applications that use these practices, well an awful lot of applications are being written using the Spring framework as their heavy lifter of choice. As for Inversion of Control, well-written/architected applications have been using the hollywood principle for years - it really isn't anything new.
Now, forget all of that and lets talk about Intentional Programming :-P
In Java Swing, from a JFrame object, you say
myWidget = new MyWidget(this);
getContentPane().add(myWidget, BorderLayout.CENTER);
This is a blatent Demeter violation now, isn't it? Or is it only a Demeter violation of either the strong or the weak form of Demeter depending on whether invoking the function getContentPane() to return an internal object of the JFrame from a derived class is considered OK or not?
When structured programming came out, it was pretty obvious what kind of mess you had with GOTOs. When Glenford Meyers came out with his "coupling" and "module strength" criterea for function modules, it was pretty obvious what kind of mess you had with global variables or with bundling sets of variables into structs simply to cut down on the parameter lists of functions.
But with this Law of Demeter business, I am just not seeing what the fuss is, especially when you have to make programs a lot more complex with forwarding functions and convoluted applications of the Visitor pattern to avoid invoking a function on an object contained in another object.
I mean c'mon people. One of the big uses of object-oriented programming is GUIs, and everyone's GUI has this layered structure of frame object-graphics object-font object where you make some kind of call like myFrame.getGraphics().setFont(myFont). A lot of this is not that the Graphics object is some kind of mystery thing that you have to keep from users of the Frame object, but Frame and Graphics are most likely interfaces to some underlying implementation, and the reason for separate Frame and Graphics interfaces instead of giving Frame forwarding methods to every freakin' method of Graphics is to organize gobs of interface functions in some logical hierarchy.