Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Interview: Ramnivas Laddad on AOP Design, Modelling, and Policy Enforcement

Interview: Ramnivas Laddad on AOP Design, Modelling, and Policy Enforcement

Ramnivas Laddad talks about domain aspects, how aspects fit in the design phase, how to model aspects in UML, how to enforce policies with Aspects, how he used Aspects to diagnose production problems including touch threading problems, and using aspects to simplify design pattern implementation.

Watch Ramnivas Laddad on AOP Design, Modelling, and Policy Enforcement (21:16 min)

One particular interesting use of Aspects Ramnivas mentions involved enforcing single-threaded use: <blockquote>I will give you an example that was my first serious aspect that really helped me solve some problems. I was working on a Swing based project and used to get some intermittent problems, you suspected that it was some threading related issues. You might be aware that Swing is a single-threaded library, that means you are not supposed to call Swing components from any thread other than dispatcher thread. So we had this problem which showed up only once in a while, and for some reason whenever we gave it to customers that problem would show up for sure. We did a couple reviews, and spotted some points, but not really anything that helped us. So I wrote a small aspect that said: "Make sure that whenever a UI component is updated the caller thread is in the dispatch thread, if it is not then report it". So we compiled our code with this aspect, and just used that code in the jar file for a few days, just normal usage. And at the end of the day we got a lot of output that told us all the places the violation was happening (and the callstacks). So we knew exactly why it happened. And that time if I remember correctly it was AspectJ .8 version. So obviously I did not want to put that code in production, it was not the right thing to do. So I basically implemented the correct code manually so Aspects helped me to enforce the policy of single threaded rule.</blockquote>

See also the considerable amount of content on AOP at:

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Concrete example of Business aspects

    by Karthik N,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Anyone know of any more Elaborate examples of using AOP/Aspectj for business aspects? I know the interview can over only so much in-depth.

  • Re: Concrete example of Business aspects

    by Rickard Öberg,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    We use AOP for our entire domain model in our app. Currently we have 168 mixins that are used in various combinations in objects, and here are some examples:
    * ACL
    * Metadata
    * User info (matches user, group, container in LDAP)
    * Parent/child relationships (one for child, one for parent/container)
    * Icon and displayname (there are lots of different variants of this, for different objects)
    * File info
    * Site/Page/Layout/Portlet and other CMS-related mixins
    * Hit counter (also CMS related)
    and so on...

    That was mixins. Then we also have 130+ interceptor style aspects that maintain various domain rules. Many are related to lifecycle management of aggregated objects (e.g. remove aggregated objects when owning object is removed), and many are related to maintaining various rules (e.g. if an object is added to a container, then the child->parent relationship must be properly updated). These interceptors are all specific to some few number of methods in some specific mixin (i.e. they are not widely applicable to many different mixins and methods), but they ARE heavily reused anyway since the mixins are reused in many domain objects.

    We also sometimes use interceptor aspects to define method parameter validation rules, so that these are not hardcoded in the various methods and mixins.

  • Re: Concrete example of Business aspects

    by Floyd Marinescu,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    On's code base Alexandru Popescu used AspectJ to add things like discussion threads and the topic/tag categorization to content items at runtime. It's a nice implementation - domain objects (articles, videos, books) don't need to know about the discussion threads associated with them or how they are categorized, those get added in as introductions afterwards.

    We can even do some cool things like havin articles and news posts announcing them share the same discussion threads.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p