The Artima Developer Community
Sponsored Link

Java Buzz Forum
AOP Kata: Reusable Aspects

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
AOP Kata: Reusable Aspects Posted: May 6, 2004 8:33 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: AOP Kata: Reusable Aspects
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement
There are certain aspects that are ripe for reuse. There are various levels of reuse of course (totally generic: Log4J, company-reuse: YourCompanyLogger, etc). A common pattern that you run into, (we use it in aTrack. Ramnivas has it in his book, etc) is that you want to apply some advice, but only to a subset of your code. The simple way to do this is to use the template pattern: First, define the abstract aspect which does most of the work, but leave open a scope() pointcut: public abstract aspect PolicyEnforcement {   pointcut printing():     get(* System.out) || get(* System.err) ||     call(* printStackTrace());   declare error: scope() && printing():     "Our policy enforces the fact that you have to print via our logger";   declare warning:     call(Exception.new()) ||     call(RuntimeException.new()) &&     scope():     "constructing exception without … a cause."; } Now, create a concrete aspect which provides the scope: public aspect DionsPolicyEnforcement extends PolicyEnforcement {     protected pointcut scope() : within(com.almaer..*); } In this example scope() was used, and is common... however you can of course create and abstract pointcuts which make sense for your problem, and have other classes provide those impls. You will often find common pointcuts such as scope(), and you will create your own within your projects.

Read: AOP Kata: Reusable Aspects

Topic: Textile enabled for comments Previous Topic   Next Topic Topic: De-crufty PHP Movable Type goodness

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use