title: Implement interface in methods (the best practice)
body: <p>I have some callback interface:</p>
  
  <pre><code>public interface FooCallback {
      boolean doSomething(Foo fooArg);
  }
  </code></pre>
  
  <p>which is implemented as anonymous block in methods in service layer:</p>
  
  <pre><code>public void methodA(Bar barArg) {
      // some business logic like parsing Foo object from Bar for example
  
      FooCallback cb = new FooCallback() {
          @Override
          public boolean doSomething(Foo fooArg) {
              // some calculation with fooArg and barArg and return boolean value
          }
      }
      saveBar(barArg, cb);
  }
  </code></pre>
  
  <p>saveBar is method which is also in that class and is using to save Bar object into database depends on result of <code>doSomething</code> method of <code>FooCallback</code>;</p>
  
  <pre><code>public void saveBar(barArg, cb) {
      // get Foo object from database
  
      if (cb.doSomething(fooFromDB)) {
          // save barArg into DB
      } else {
          // antother logic
      }
  }
  </code></pre>
  
  <p>I have a lot of methods like <code>methodA</code> in my service class. Anonymous code block is also bad testable. Can you tell me what is the best practice with similar implementation? I figure out move content from <code>doSomething</code> to another method, but it means every method will be self methodCallback. What do you think? I am using java. Thank you in advice.</p>