title: Calling virtual method in base class constructor
body: <p>I know that calling a virtual method from a base class constructor can be dangerous since the child class might not be in a valid state. (at least in C#)</p>
  
  <p>My question is what if the virtual method is the one who initializes the state of the object ? Is it good practice or should it be a two step process, first to create the object and then to load the state ?</p>
  
  <p>First option: (using the constructor to initialize the state)</p>
  
  <pre><code>public class BaseObject {
      public BaseObject(XElement definition) {
          this.LoadState(definition);
      }
  
      protected abstract LoadState(XElement definition);
  }
  </code></pre>
  
  <p>Second option: (using a two step process)</p>
  
  <pre><code>public class BaseObject {
      public void LoadState(XElement definition) {
          this.LoadStateCore(definition);
      }
  
      protected abstract LoadStateCore(XElement definition);
  }
  </code></pre>
  
  <p>In the first method the consumer of the code can create and initialize the object with one statement:</p>
  
  <pre><code>// The base class will call the virtual method to load the state.
  ChildObject o = new ChildObject(definition)
  </code></pre>
  
  <p>In the second method the consumer will have to create the object and then load the state:</p>
  
  <pre><code>ChildObject o = new ChildObject();
  o.LoadState(definition);
  </code></pre>