Skip to main content

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

Thanks for the replies,  yeah I knew around advice could be used to trap the
original method invocation and either route it to new behaviour or add new
behaviour in the advice but doesn't the old behaviour still exist or is it
removed?
Cheers
Neil




----- Original Message ----- 
From: "Macneil Shonle" <mshonle@xxxxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Sent: Wednesday, October 08, 2003 5:52 PM
Subject: Re: [aspectj-users] accessing specific instances with AspectJ and
overwriting query


> Hi Neil,
>
> > 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.
>
> You can refactor your code to expose s3. For example you can construct s3
> via a special method called newColorShape. You then know whenever
> newColorShape it returned that it has the object you want.
>
> > 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 think around advice is probably what you want here. I'm not quite sure
> what you mean by code bloat because the overhead is minor. If you just
> like the notational ease of saying "overwrite" then you might want to look
> into hygenic macro packages.
>
> -Macneil
>
> >
> > I'd be interested in the lists opinions (good or bad!) regarding these
> > issues.
> >
> > Cheers
> > Neil
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top