[aspectc-user] Element counter example -- getting compile error

Daniel Lohmann daniel.lohmann at informatik.uni-erlangen.de
Fri May 28 12:18:23 CEST 2004

Hi Siva,

>During the test, I have found an error in the tutorial:
>In the ErrorAspect.ah file, you have the following line:
>advice execution("% Queue::dequeue(...)") && result(item)
>But dequeue has no arguments! So I think it should be:
>advice execution("% Queue::dequeue()") && result(item)
This is actually not an error, as the ellipsis ("...") matches for any 
number of arguments (which includes no arguments). Of course, one can  
argue if this is good style. The idea here is to make the pointcut 
robust against changes in the signature of dequeue. As a result, the 
aspect will still work as expected if (e.g. during maintaince) some 
parameters are added to dequeue.

>Instead testing the item after the execution, another idea is to test the
>variable 'first' to see it that is 0. Here is the advice for that:
>advice execution("% Queue::dequeue()") && that(q):
>  before(Queue* q) {
>    if (q->first == 0) {
>      throw QueueEmptyError();
>    }
>  }
Of course it is also possible to do it this way. However, this way your 
aspect implementation is higly dependent on the internals of class Queue 
and its implementation. So the argument for the original solution is, 
once again, robustness. By testing the item after the execution, it 
depends only on the specification, but not on implementation internals 
of class Queue.



More information about the aspectc-user mailing list