title: What defines a valid object state?
body: <p>I am reading <a href="http://www.daedtech.com/beware-the-bloated-constructor/" rel="noreferrer">an article</a> about constructors doing too much work. 
  One paragraph reads </p>
  
  <blockquote>
    <p>In the object oriented style, where dependencies tend to be inverted, the constructor has a different and more Spartan role. Its only job is to make sure that object initializes into a state where it satisfies its basic invariants (in other words, it makes sure that the object instance starts off in a valid state and nothing more). </p>
  </blockquote>
  
  <p>Here is a basic example of a class. On creation of the class I pass in the HTML which needs parsed to then set the class properties.</p>
  
  <pre><code>OrderHtmlParser
  {
      protected $html;
  
      protected $orderNumber;
  
      public function __construct($html)
      {
          $this-&gt;html = $html;
      }
  
      public function parse()
      {
          $complexLogicResult = $this-&gt;doComplexLogic($this-&gt;html);
  
          $this-&gt;orderNumber = $complexLogicResult;
      }
  
      public function getOrderNumber()
      {
          return $this-&gt;orderNumber;
      }
  
      protected function doComplexLogic($html)
      {
          // ...
  
          return $complexLogicResult;
      }
  }
  </code></pre>
  
  <p>I'm calling it using</p>
  
  <pre><code>$orderparser = new OrderHtmlParser($html);
  $orderparser-&gt;parse()
  $orderparser-&gt;getOrderNumber();
  </code></pre>
  
  <p>I use a <code>parse</code> function because I dont want the constructor to be doing any logic as both the article above and <a href="http://misko.hevery.com/code-reviewers-guide/flaw-constructor-does-real-work/" rel="noreferrer">this article</a> state this is terrible practice.</p>
  
  <pre><code>public function __construct($html)
  {
      $this-&gt;html = $html;
      $this-&gt;parse(); // bad
  }
  </code></pre>
  
  <p>However if I don't use the <code>parse</code> method, then all my properties (in this example just the one) would return <code>null</code>.</p>
  
  <p><strong>Is this known as an object in an 'invalid state'?</strong></p>
  
  <p>Also, it somewhat <em>feels</em> like my parse method is an <code>initialise</code> function in disguise, which is also deemed bad by the other article (although im not sure if that is only when a constructor calls that method, when it is manually called or both). Regardless, the initialise method is still doing some complex logic prior to setting a property - which needs to happen before the getters can be reliably called.</p>
  
  <p>So either I am misunderstanding these articles or these articles are pushing me to think that maybe my overall implementation of this simple class is incorrect.</p>