Eitan Suez's Home

TextMate icon

More on AOP

Posted by Eitan Thu, 16 Mar 2006 04:10:00 GMT

Like many others, I recently read Graham Hamilton's AOP: Madness and Sanity

For some reason though, the rebuttal won't leave my mind. Maybe I can get this off my chest with a small blog entry.

OOP has inheritance. Inheritance I'm coming to think is a form of AOP. You can subclass an existing class, override a method, and voila, you can have around() advice for free:

public void overriden() { before(); super.overridden(); after(); }

Also, inheritance has already done to OOP what Graham fears will happen to programs when people start using AOP: make them confused. Many times as we read OO code, we wonder why our application is behaving in a certain way. Oftentimes we discover that we overlooked the fact that an inherited class overrode the behaviour we expected to be invoked. Or sometimes we expect to find a method or field in a class, and then say "ah, of course; it's not here because it must be declared in a superclass."

IDEs and Javadocs help us with our confusion by telling us: "this is the list of classes that extend this one," or "here is the inheritance hierarchy for this class," and so on.

So with AOP things need not be any more confusing or any different. Soon we'll be able to easily ask similar questions: "show me a list of all classes that advise this method or class," for example.

I guess what I'm trying to say is that AOP need not be looked at as something so foreign to the way we already program. Instead I like to think of it as a fairly natural extension of something we already do. We just have more flexibility in terms of how we go about solving problems, modeling things, keeping things more refactored. That's what AOP gives us. No code duplication: going from somewhat DRY to really DRY.

Posted in  | no comments

Comments

Comments are disabled


Powered