title: Abstract methods in an abstract class constructor: design flaw?
body: <p>I have an abstract class <code>Entity</code>. Every class extending <code>Entity</code> will need some default and some customizable setup:</p>
  
  <pre><code>public abstract class Entity {
  
      protected Entity() {
          // ... default setup
          customSetup();
      }
  
      protected abstract void customSetup();
      // ...
  }
  </code></pre>
  
  <p>My extending class <code>MyEntity</code> takes a parameter in the constructor, that will be used in <code>customSetup()</code>:</p>
  
  <pre><code>public class MyEntity extends Entity {
  
      private Data data;
  
      public MyEntity(Data d) {
          super(); // in here customSetup() is called!
          data = d;
      }
  
      @Override
      protected void customSetup() {
          codeDependingOn(data); // will throw NPE: data==null yet!
      }
  }
  </code></pre>
  
  <p>As comments state, this code won't work.</p>
  
  <p>I could just throw away <code>customSetup()</code> and put all the custom code after <code>super()</code>, but having that abstract method makes clearer what you're supposed to put there.</p>
  
  <p>I feel like I'm violating some rule of OOP design. What's the correct way to do what I want?</p>