InfoQ

Interview

   Good News: We have re-worked our video infrastructure to provide more reliable service. Please email bugs at infoq.com with any problems.

AOP Refactoring with Ramnivas Laddad

Interview with Ramnivas Laddad on May 07, 2007 08:00 AM

Community
Java
Topics
AOP
Tags
AspectJ
Summary
AOP expert Ramnivas Laddad explains how to use Aspects for refactoring cross-cutting concerns within classes (not just across classes) for things like reducing boiler plate code and potential for mistakes. How to recoganize and refactor such logic into aspects is covered, as well as applying aspects for resource management and concurrency control.

Bio
Ramnivas Laddad is an author, speaker, consultant, and trainer specializing in aspect-oriented programming and J2EE. His most recent book, "AspectJ in Action: Practical aspect-oriented programming" (Manning, 2003), has been labeled as the most useful guide to AOP/AspectJ. Ramnivas works for Interface21, providers of Spring.
Ramnivas can you please introduce yourself and tell us what you're up to?
How would one go about adopting AOP?
What are refactoring aspects?
Can you give us some examples on what kind of code we can refactor into aspects?
Most people think of aspects for modularizing cross-cutting concerns across objects. But you're talking about cross methods. Isn't that going a bit too far?
When one should put an aspect within an object versus externalized?
You mentioned in the past that concurrency and resource management are also good applications for aspects. Can you explain ?
What about concurrency? How can aspects be used to refactor concurrency control?
Isn't it dangerous to lose the explicitness of putting in the code? If you get used to not coding in these constructs and you're used to relying on aspects, what if you forget to assign your point-cut?
You mentioned that you could find yourself doing repetition even within aspects. Can you give us an example? How would you solve that problem?
Any final words on AOP refactoring?
show all  show all

3 comments

Reply

Not a good example by Cristian Herling Posted May 8, 2007 4:55 PM
Re: Not a good example by Ramnivas Laddad Posted May 8, 2007 9:09 PM
Re: Not a good example by Cristian Herling Posted May 9, 2007 9:16 AM
  1. Back to top

    Not a good example

    May 8, 2007 4:55 PM by Cristian Herling

    "Whole try-catch blocks repeated in many methods" and "code that repeats across multiple methods in one class" are a code smell, a sign of bad design. There are valid OOP ways to tackle these problems, we don't need to throw AOP into this mix for solving this problem (if anything, the problem becomes more complex). I find AOP to be most successful at injecting behavior which should be kept outside of objects into the objects themselves. This interview is an example of injecting object-specific behavior into an object thru aspects, I think that we are using a sledge-hammer to knock out a mosquito.

  2. Back to top

    Re: Not a good example

    May 8, 2007 9:09 PM by Ramnivas Laddad

    C H, Take a look at http://www.theserverside.com/tt/articles/article.tss?l=AspectOrientedRefactoringPart1 and http://www.theserverside.com/tt/articles/article.tss?l=AspectOrientedRefactoringPart2. Which valid OOP ways can tackle the examples discussed? We can have beneficial discussion if you can show OO-based versions of the classes shown. Then we can compare and contrast two ways of doing the same thing. -Ramnivas

  3. Back to top

    Re: Not a good example

    May 9, 2007 9:16 AM by Cristian Herling

    The example you mention is actually valid, I wished that in the interview you would have gone a bit more in detail, mentioning only that you would use AOP for getting rid of code that is repeated across methods is a bit confusing. If anything it raises the possibility of bad design (this is the first thing I think of when I hear these words). I would have added the link from your reply to the interview and would have referred to it during the interview, it would have made a few things a lot more clearer. I have 2 things to say about this example however: 1) The aspect that you apply to the methods in questions is really a small part of a large cross-cutting concern: security. I get the feeling that the "micro-cross-cutting concern" should actually be part of a larger cross-cutting concern. If you are using a security micro-cross-cutting concern in Account.java and another one in PurchaseOrder.Java and yet another one in PeopleDirectory.java, you are basically spreading security handling all over the code-base. I get the feeling that these micro-cross-cutting concerns should be consolidated into one larger concern. Please let me know what you think about this. 2) I think you can still go OOP in order to solve the problem by using decorators (declare interface Account and implementations SecuredAccount and RegularAccount, SecuredAccount having a link to an Account). Decorators don't react well to interface changes: let's say that you need to add another method to the interface Account, all the implementations will have to be changed, but this is the overhead for using them. I still think that the example of micro-cross-cutting concerns takes AOP a bit too far. However, I found the examples at the beginning of the interview very interesting because they apply AOP to cross-cutting concerns.

Exclusive Content

Tapestry for Nonbelievers

A new article by I. Drobiazko and R. Zubairov introduces v. 5 of the Apache Tapestry component-oriented web framework. The tutorial shows how to create a component and covers IoC in Tapestry and Ajax.

Pete Lacey on REST and Web Services

In this interview, Burton Group consultant Pete Lacey talks to Stefan Tilkov about his disillusionment with SOAP, his opinion on REST, and addresses some of the perceived shortcomings REST vs. WS-*.

Business Natural Languages Development in Ruby

Jay Fields presents his concept of Business Natural Languages - a type of Domain Specific Languages geared towards being readable by domain experts.

Distributed Version Control Systems: A Not-So-Quick Guide Through

Adoption and interest for Distributed Version Control Systems is constantly rising. We will introduce the concept of DVCS and have a look at 3 actors in the area: git, Mercurial and Bazaar.

Segundo Velasquez and Agile as Seen Through the Customer's Eyes

Deborah Hartmann interviewed Segundo Velasquez about his experience as customer with an Agile team during the initial phase of software design of a product.

Fine Grained Versioning with ClickOnce

David Cooksey shows how to fine grained versioning to a ClickOnce deployment using an HttpHandler written with ASP.NET, making partial rollouts to a test audience much easier.

Implementing Manual Activities in Windows Workflow

Windows workflow (WF) is an excellent framework for implementing business processes, but lacks support for human activities. This article describes a completely generic approach for changing this.

Markus Voelter about Software Architecture Documentation

In this interview taken during OOPSLA 2007, Markus Voelter talks about the importance of documenting the software architecture, and gives some good and also bad examples on how it could be done.