title: How to create a blueprint for new classes
body: <p>To improve my knowledge about coding I want to build a library with as much patterns, containers and simular stuff as possible.</p>
  
  <p>I don't want to implement the patterns itself but rather want to describe them. For example, I don't want the library to contain an observer but rather when the main project requires an observer, I can just add <code>extends observer</code> or <code>implements observer</code> and the IDE should auto-complete it as far as possible. </p>
  
  <p>To start of easy (atleast I thought so) I wanted to start with the (anti-)pattern for a Singleton.</p>
  
  <p>I created an Interface <code>iSingleton { iSingleton getInstance(); }</code>, together with an abstract class</p>
  
  <pre><code>public abstract class Singleton implements iSingleton
  {
      static Singleton instance;
  
      protected Singleton() {}
  }
  </code></pre>
  
  <p>and of course I created an implementation test class</p>
  
  <pre><code>public class Test extends Singleton
  {
      private Test();
  
      public Test getInstance()
      {
          if (instance == null)
          {
              instance = new Test();
          }
  
          return (Test) instance;
      }
  }
  </code></pre>
  
  <p>However this gave a few issues</p>
  
  <ul>
  <li>I didn't have to create <code>private Test</code></li>
  <li>Test test = Test.getInstance(); cannot be called from non-static context</li>
  <li>I have to cast the return value in getInstance</li>
  </ul>
  
  <p>What I want is a class/interface that tells and allows me to build something like this</p>
  
  <pre><code>public Implementation extends/implements Singleton
  {
      static Implementation instance;
  
      private Implementation()
      {
          // It's a singleton, use getInstance()
      }
  
      public static Implementation getInstance()
      {
          if (instance == null)
          {
              instance = new Implementation()
          }
  
          return instance
      }
  }
  </code></pre>
  
  <p>The specifics I would like</p>
  
  <ul>
  <li>tell the implementation class to have a (static) variable of itself</li>
  <li>tell the implementation class to have a private constructor</li>
  <li>tell the implementation class to have a static method called getInstance</li>
  </ul>
  
  <p>How can I create something like and is it even possible?</p>