title: Java interfaces, the creator patterns and the "getInstance()" method or equivalent
body: <p>I would like to start off by mentioning that my problem stems from the fact that interfaces in Java do not allow static methods. There have been discussions about the reason for this on SO (<a href="https://stackoverflow.com/questions/129267/why-no-static-methods-in-interfaces-but-static-fields-and-inner-classes-ok">here</a> , for example). So lets not dwell on that. I am looking for a way for my interface to create an instance of itself (rather, its implementation) and return that. In spite of playing around with Singleton pattern, Factory and AbstractFactory patterns, I still cannot achieve my goal.</p>
  
  <p>To elaborate on what I'm trying - here's my interface:</p>
  
  <pre><code>public interface NoteDataStore {
      public boolean deleteNote(long noteId);
      public boolean addNote(Note note);
      public List&lt;Note&gt; listNotes();
      public boolean editNote(long noteId, Note note);
      public List&lt;Note&gt; search(String searchString);
  }
  </code></pre>
  
  <p>And here's my business logic layer:</p>
  
  <pre><code>public class BusinessLogicLayer {
  
      public BusinessLogicLayer(){
          /*
           * GOAL: To get an instance of NoteDataStore here,
           *  without being aware of the implementation class.
           */
      }
  
  }
  </code></pre>
  
  <p>I tried to use a factory pattern like so:</p>
  
  <pre><code>public interface NoteDataStoreFactory {
      public NoteDataStore getDataStoreInstance();
  }
  
  public class NoteDataStoreFactoryImpl implements NoteDataStoreFactory{
      public NoteDataStore getDataStoreInstance(){
          return NoteDataStoreImpl.getInstance();
          /*
           * Here, NoteDataStoreImpl is an implementation of NoteDataStore.
           * This should be transparent to my business logic layer.
           */
      }
  }
  </code></pre>
  
  <p>However, this still requires the Business Logic layer to know the implementation class <code>NoteDataStoreFactoryImpl</code> thus:</p>
  
  <pre><code>NoteDataStore = new NoteDataStoreFactoryImpl().getDataStoreInstance();
  </code></pre>
  
  <p>How do I get around this? How do I keep my BusinessLogicLayer in the dark regarding the exact implementation class to use?</p>
  
  <hr>
  
  <h2>EDIT: More Detailed Background of my problem</h2>
  
  <p>A few of the answers suggest the use of frameworks like Spring. Alas, I cannot do so because this application targets various mobile platforms (Android, Blackberry, JavaME). I should have made this clear in my original question - apologies for not doing so.</p>
  
  <p>My main intention is to have an app across platforms. The UI, database access, HTTP transport layers etc will have to be coded specifically for each platform. However, the business logic is simple enough to warrant a common layer across all platforms. I intend to distribute the business logic layer as a JAR library. So also, the parsing and framing layer (for JSON/XML).</p>
  
  <p>There has already been a discussion about this at SO (on whether I should even be going down this path) - <a href="https://stackoverflow.com/q/6636050/570930">Logic Code reuse</a>. However, assuming this is OK and that I proceed with the layered approach and the intention to have one layer common in code. Now, my situation is such that I have:</p>
  
  <ol>
  <li>A common Business Logic Layer.</li>
  <li>Platform-specific data layer (represented by the <code>NoteDataStore</code> interface)</li>
  <li>Platform-specific Application core layer (Controller, if I may call it so).</li>
  </ol>
  
  <p>Note that if I use the Factory pattern or other such, I can afford to have that layer specific to each platform. So, the factory method/class itself can know about the <code>NoteDataStore</code> implementation class. However, the Business Logic Layer must be unaware of any of the implementation classes.</p>
  
  <p>A typical use of the various layers would be as follows:</p>
  
  <pre><code>public class NoteDataStoreAndroid implements NoteDataStore{
  
      public boolean deleteNote(long noteId){
          /*
           * Android-specific database code
           */
      }
  
      /* ... similarly, other methods */
  }
  
  
  public class AndroidCoreApp{
  
      public void doBusinessLogic(){
          BusinessLogicLayer businessLogic = new BusinessLogicLayer();
          businessLogic.startBusinessLogic();
      }
  }
  </code></pre>
  
  <p>Any inputs on how to handle this scenario?</p>