| Re: [aspectj-users] Super calls to inter-type methods |
| There's a limited way to do it if you use the Template Method Pattern. However, it's got "issues", too. Comments inline: On Mar 12, 2008, at 11:23 AM, Dave Whittaker wrote: Hi there. I'm having trouble figuring out the best method to do something and I was hoping someone out there with more AspectJ experience might be able to help. public aspect SelectAspect { private T SelectAction<T>.selection; // Template Method pattern: public void SelectAction<T>.select(T selection) { before(selection); this.selection = selection; after(selection); } // Must declare these default implementations public: public void before(T selection) {} public void after(T selection) {} }
public void before(String selection) { checkPermissions(selection); }
This avoids having to call super. In fact, I almost always use Template Method in cases like this, with pure objects, because calling super is a bit of an "anti-pattern", because it would be easy to do the wrong thing; (i) forget to call super, (ii) call it at the wrong time, (iii) change the "contract" of the method unexpectedly, etc. Template Method helps nail those problems down. The two big drawbacks of this "trick" are (i) the Eclipse java editor shows an error indicator on the class name, claiming that it needs to implement the methods defined by the interface, even though everything builds fine if you use ajc, (ii) it can be confusing to the person who gets to maintain the code after you. ;) dean
Dean Wampler, Ph.D. dean at objectmentor.com See also: http://www.aspectprogramming.com AOP advocacy site http://aquarium.rubyforge.org AOP for Ruby http://www.contract4j.org Design by Contract for Java5 |