Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Perobject association (was: [aspectj-dev] pertypewithin() vs. pertype() association...)

Hi all.

> P.P.S. - Eric, re:
> > I have actually found
> > quite some use cases where you want to associate aspect instances with
> > a certain object which is *not* necessarily exposed through a given
> > pointcut.
> It would be useful to post about these cases, at least to
> see if there are any workarounds.

Ok, I think I mentioned this already a few months ago in a somewhat
different context. One use case for example is for instance if I want to
reason about certain objects being created by a factory method, say
"getInstance()". So for example I want to say "For each instance created by
Factory.getInstance(), associate an aspect with this instance which tracks
its lifecycle.". In our particular, we would be using this for a runtime
verification approach.

For example, what I would like to be able to express is:

At the moment, I *think* the only way is...

a) to use inter type declerations to store object-dependent state within the
object instead the aspect. This however only works for reference types (I
cannot use inter type declerations let's say on an "int", can I?), or...

b) use HashTables or similar to associate such state with a certain object.

Please correct me if I am wrong.

An *informal* approach of what I am trying to formulate would be something
like the following:

aspect Tracking perreturn(call(* Object Factory.instanceOf()) {

    //some pieces of advice checking certain conditions
    //during the lifecycle of the associated object

}

with "association aspects" this could easily be implemented using an
explicit instantiation with "associate":

aspect Tracking perobject(Object) {

    after() returning(Object o): call(* Factory.instanceOf()) {
        associate(o);
    }

}

This would also make the pertype-thingy only a special case since one could
easily formulate a pertypewithin(<TypeExpression>) as something like:

aspect aspect perobject(Object) {

    after(): staticinitialization(Object o) {
        associate(o);
    }

}

I really think that this is a powerful and elegant extension to AspectJ. The
aforementioned paper as well as this one explain further applications quite
a bit: "Implementation of Contracts using Association Aspects Notated code"
(http://tinyurl.com/44c7a).

Would be great if you could support this powerful feature at least in the
long term!

Thank you a lot,

Eric





Back to the top