0 Replies Latest reply on Jul 3, 2006 1:46 PM by Kabir Khan

    Advices for inherited methods

    Kabir Khan Master

      I've revisited how bindings for inherited methods work http://jira.jboss.com/jira/browse/JBAOP-154, to be more similar to how overridden methods work.

      class POJO{
       void test();
       void test2();
      }
      
      class Sub1 extends POJO{
      
      }
      
      class Sub2 extends POJO{
       void test();
       void test2();
      }
      
      <aop>
       <bind pointcut="execution(* POJO->*())">
       <interceptor class="A"/>
       </bind>
       <bind pointcut="execution(* Sub*->test())">
       <interceptor class="B"/>
       </bind>
      <aop>
      
      POJO pojo = new POJO();
      pojo.test(); //Gets intercepted by A
      Sub1 sub1 = new Sub1();
      sub1.test(); //Gets intercepted by B
      Sub2 sub2 = new Sub2();
      sub2.test(); //Gets intercepted by B
      


      The one limitation is that the inherited methods must be at least prepared for the hooks to be introduced. I'm happy with how the above example works, but in the case of

       <bind pointcut="execution(* Sub*->*())">
       <interceptor class="C"/>
       </bind>
      


      C will replace all the bindings for test2(). Semantically it is identical to the first example, but there is scope for unintentionally overriding the wrong thing. I'm wondering if I should maybe only make this functionality available for specifically overridden methods not using wildcards? e.g

       <bind pointcut="execution(* Sub*->*())">
       <interceptor class="C"/>
       </bind>
      


      will only match methods actually overridden in the subclass, and

       <bind pointcut="execution(* Sub*->test2())">
       <interceptor class="C"/>
       </bind>
      


      overrides the chains for test2().