• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why empty pointcut?

 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm total newbie to AspectJ - so I might be missing something very obvious.

I went through few articles online and found a typical practice:

There is an empty pointcut 'p' (i.e. an empty method with @Pointcut annotation) - having an expression 'e' (which matches a set of methods). Further, there is an advice 'a' - which is written for pointcut 'p'.

My question is - what is purpose of empty pointcut? I tried and found that I do not need empty pointcut. I can directly write an advice 'a' for an expression 'e'.

Thanks in advance.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you do not define that empty @Pointcut method (which does not necessarily have to be empty), but instead define it on the advice it is referred to as an anonymous or un-named pointcut. You can draw a parallel to an anonymous class in Java. This is fine for simple point cuts but it suffers the same downsides of an anonymous class specifically it cannot be reused and is not as readable or maintainable. When you use the empty method it can be referenced from many advices and the name of the method can clearly specify the purpose of the pointcut expression.

HTH
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill. Its quite clear now.

So, by defining a pointcut, I don't have to copy-paste expression for all my advises right? (and in future, if I want to change the expression, I would change it only at one place)
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats correct you would do something like this:



Its clear now that someAdvice is applied to allOperations just by looking at it, and other advices can use the Pointcut as well.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic