title: Why Spring-proxy uses delegate pattern instead of inheritance+super?
body: <p>As we all know, the self-invokation of bean's method is not working in Spring without AspectJ.</p>
  
  <p>See <a href="https://stackoverflow.com/questions/1099025/spring-transactional-what-happens-in-background">this question</a> for example.</p>
  
  <p>I think this is because the Spring-created proxy calls the target object's methods using delagate pattern. Like this:</p>
  
  <pre><code>class MyClass {
  
      @Autowired
      private MyClass self; // actually a MyProxy instance
  
      @Transactional // or any other proxy magic
      public void myMethod() {}
  
      public void myOtherMethod() {
          this.myMethod(); // or self.myMethod() to avoid self-invokation problem
      }
  }
  
  class MyProxy extends MyClass { // or implements MyInterface if proxyMode is not TARGET_CLASS and MyClass also implements MyInterface
  
      private final MyClass delegate;
  
      @Override
      public void myMethod() {
          // some proxy magic: caching, transaction management etc
          delegate.myMethod();
          // some proxy magic: caching, transaction management etc
      }
  
      @Override
      public void myOtherMethod() {
          delegate.myOtherMethod();
      }
  }
  </code></pre>
  
  <p>Am I right?</p>
  
  <p>With this code:</p>
  
  <pre><code>public void myOtherMethod() {
      this.myMethod();
  }
  </code></pre>
  
  <p><code>this.myMethod()</code> will bypass the proxy (so all <code>@Transactional</code> or <code>@Cacheable</code> magic) because it is just internal delegate's call... So we should inject a <code>MyClass</code> bean (which is actually is <code>MyProxy</code> instance) inside <code>MyClass</code> and call <code>self.myMethod()</code> instead. It is understandable.</p>
  
  <p>But why the proxy is implemented this way?
  Why it is not just extends the target class, overriding all public methods and calling <code>super</code> instead of <code>delegate</code>?
  Like this:</p>
  
  <pre><code>class MyProxy extends MyClass {
      // private final MyClass delegate; // no delegate
      @Override
      public void myMethod() {
          // some proxy magic: caching, transaction management etc
          super.myMethod();
          // some proxy magic: caching, transaction management etc
      }
      @Override
      public void myOtherMethod() {
          super.myOtherMethod();
      }
  }
  </code></pre>
  
  <p>It should solve the self-invokation problem, where <code>this.myMethod()</code> bypasses the proxy, because in this case <code>this.myMethod()</code>, invoked from <code>MyClass.myOtherMethod()</code> (we remember that MyClass bean actually is MyProxy instance), will invoke overriden child's method (<code>MyProxy.myMethod()</code>).</p>
  
  <p>So, my main question is <strong>why it is not implemented this way?</strong></p>