title: "Inject" interface implementions into a class in java
body: <p>I'm wrting something that look like this (of course its a bit more complex than this sample):</p>
  
  <pre><code>public class DoOnAll {
  
      private List&lt;IActionPerformer&gt; actionPerformers;
  
      public DoOnAll(List&lt;IActionPerformer&gt; actionPerformers) {
          this.actionPerformers = actionPerformers;
      }
  
      public void callFromSomeWhere(String path) {
          File f = new File(path);
          List&lt;File&gt; list = Arrays.asList(f.listFiles());
          for (File file : list) {
              for (IActionPerformer action : actionPerformers) {
                  action.perform(file);
                 }
          }
      }
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public interface IActionPerformer {
      public void perform(File file);
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class SomePerformer implements IActionPerformer {
  
      public void perform(File file) {
          if (getFileType(file) = ".txt") {
              doSomething
          }
      }
  }
  </code></pre>
  
  <p>I have 2 questions:</p>
  
  <ol>
  <li><p>Should I move the condition in <code>SomePerformer</code> to another method, <code>boolean accept(File file)</code> for example, and also add this method declartion to the interface?
  If so, how would I "collect" all the accepted classes in <code>DoOnAll</code>? just go through the <code>actionPerformers</code> list and add all the accepeted  to another list and then go through the list of accepted and <code>.perform</code> on them? Or is there another way usually used in the methodology?</p></li>
  <li><p>Which ways are there for injecting the <code>actionPerformrs</code> list into the class? 
  I want to write independent implementations and define in a file, say xml file, which ones to inject into the list.</p></li>
  </ol>