Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

4.1. Advice overview

Dynamic crosscutting weaving rules consist of two parts: advice (what to do) and pointcuts (when to apply the advice). AspectJ supports dynamic crosscutting through advice—a method-like construct that defines crosscutting action at the join points selected by a pointcut. We'll begin with discussing three kinds of advice followed by the general anatomy of advice.

4.1.1. Advice classification

If you're implementing a security check, you want that check to take place before executing the join point. On the other hand, if you're implementing exception logging, you want to log after executing the join point and only if it threw an exception. If you're implementing caching, you want to surround the original code with the caching logic: obtain a value from the cache, execute the original code if the cache doesn't contain a value, and add the value to the cache after executing the original code. To take care of all these scenarios, AspectJ offers three kinds of advice:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial