Relational aspects as tracematches (and "relational tracematches")

Eric | November 1, 2007

Different storage structure of association aspects, the relationship aspects library and relational aspects (our own approach)The relationships between objects in object-oriented applications are an essential property of the program’s design and implementation. Two previous approaches to implement relationships with aspects were association aspects, an AspectJ-based language extension, and the relationship aspects library. While those approaches greatly ease software development, we believe that they are not general enough. For instance, the library approach only works for binary relations, while the language extension does not allow for the association of primitive values or values from non-weavable classes.

Hence, in our work we proposed a generalized alternative implementation via a direct reduction to tracematches, a language feature for executing an advice after having matched a sequence of events.

This new implementation scheme yields multiple benefits. Firstly, our implementation is more general than existing ones, avoiding most previous limitations. It also yields a new language construct, relational tracematches.


We provide an efficient implementation based on the AspectBench compiler, along with test cases and micro-benchmarks. Our empirical studies showed that our implementation, when compared to previous approaches, uses a similar memory footprint with no leaking, but the generality of our approach does lead to some runtime overhead. We believe that our implementation can provide a solid foundation for future research.

The following code snippet shows a relational aspect in action.

relational abstract aspect SimpleObserver(Subject s, Observer o) {

    abstract pointcut subjectChanged(Subject subj);

    relational after(): subjectChanged(s) {
        o. notify(s );
    }

}

This aspect implements the well-known Observer pattern in which a set of observers is to be notified about certain observable changes in the state of a particular subject. With this aspect, all the client code has to do is call:

SimpleObserver.associate(mySubject,myObserver);

This will then automatically register this pair of objects with the aspect. Then, whenever the subject is updated, the after-advice in the relational aspect is executed. Conversely, the advice will not execute if a subject is updated that was not registered with the aspect. Hence, relational aspects can be used to attach semantics to groups of objects, implementing collaborations in a modular way.

Download the full paper here.