Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] accessing specific instances with AspectJ and overwriting query

Okay I have 2 general queries that have always been in my mind using AspectJ

1.    Suppose I have a class which contains the following

    Shape s1 = new Shape();
    Shape s2 = new Shape();
    Shape s3 = new Shape();
    Shape s4 = new Shape();

   I don't think its possible to write an aspect to get a handle on s3 alone
in order to, say, change the colour from the aspect..

    I have written an aspect in the past which simply counts how many
instances have occured (in the above case 3) in order to get the handle but
this always felt a     hack.. and may not be suitable once the system
evolves in much the same way that advice on line numbers is a poor solution.

2.    Also in some cases I've found that I require aspects to "overwrite"
existing methods in classes rather than merely wrap them which can cause
code                 bloat.  I've often thought that the keyword "overwrite"
might be useful with introductions where we can overwrite methods that are
already defined.

 class MyClass {
     public void method() {..}
    }


aspect A {
    overwrite public void MyClass.method() {.. new implementation }
    }


I'd be interested in the lists opinions (good or bad!) regarding these
issues.

Cheers
Neil



Back to the top