Alex headshot

AlBlue’s Blog

Macs, Modularity and More

Is Aspect Oriented Programming the next big thing?

2004

If you've been following recent developments in the OO programming community, you can't help but think that Aspect Oriented Programming is going to be big. A lot has been done with AOP; both from the theoretical community and also from the programming community.

However, I really liked the quote from Gosling about it:

AOP is kind of a complicated one for me, because AOP is one of these things where the theory sounds really good. I actually mostly like the theory. The way it turns out in practice tends to be pretty dangerous. It's fraught with all kinds of problems. You know when the AOP folks talk about AOP they list you like three or four use cases for AOP and they actually mostly make sense, although they have problems in the details. But there actually aren't very many use cases outside of that.

To explain, I need to give a simplistic view of what AOP is. Essentially, AOP allows you to insert (crosscut, in AOP terms) code to the start and/or end of a method:

Before AOPAfter AOP
public void doSomething() {
  // normal code
}
public void doSomething() {
  // AOP inserted code goes here
  // normal code
  // AOP inserted code goes here
}

So there are several things that AOP can be used for:

  • Generating logging statements
  • Handling errors or exceptions
  • Performing checks, such as security or assertions

The problem is (and the one Gosling highlighted) is that whilst AOP actually has an interesting idea, the application of that idea is limited to certain patterns. In effect, AOP is a pattern in the same way that Command or Visitor is a pattern -- but we don't talk about Visitor-oriented programming. I think the same is true of the Inversion Of Control or IOC, which is in essence, how the Command and Visitor patterns work. Whilst both Command and Visitor have their uses, I wouldn't recommend that an application be solely built out of those patterns.

So, is AOP the next big thing? I think it is just as big as IoC or any design pattern; they are good for certain uses, but not for everything. Like design patterns, AOP is a good technique to have under the belt and to use it for certain things; but that doesn't mean everything has to (or even should) use it. I certainly disagree with Marc Fleury's views in the same article as to how J2EE is all AOP -- whilst JBoss 4.0 uses AOP extensively to determine security and transactions in JBoss AOP, that's just one implementation. I could equally well use a Command pattern to achieve the same effect.

Developers (and designers) always have to be aware of new technologies, and new approaches to solving problems. Aspect Oriented Programming is a good tool for solving some specialised problems; but one tool does not a toolbox make.