title: DDD and MVC: Difference between 'Model' and 'Entity'
body: <p>I'm seriously confused about the concept of the 'Model' in MVC.  Most frameworks that exist today put the Model between the Controller and the database, and the Model almost acts like a database abstraction layer.  The concept of 'Fat Model Skinny Controller' is lost as the Controller starts doing more and more logic.</p>
  
  <p>In DDD, there is also the concept of a Domain Entity, which has a unique identity to it.  As I understand it, a user is a good example of an Entity (unique userid, for instance).  The Entity has a life-cycle -- it's values can change throughout the course of the action -- and then it's saved or discarded.</p>
  
  <p>The Entity I describe above is what I thought Model was supposed to be in MVC?  How off-base am I?</p>
  
  <p>To clutter things more, you throw in other patterns, such as the Repository pattern (maybe putting a Service in there).  It's pretty clear how the Repository would interact with an Entity -- how does it with a Model?</p>
  
  <p>Controllers can have multiple Models, which makes it seem like a Model is less a "database table" than it is a unique Entity.</p>
  
  <p><strong>UPDATE:</strong> <a href="http://www.codinghorror.com/blog/2008/05/understanding-model-view-controller.html" rel="noreferrer">In this post</a> the Model is described as something with knowledge, and it can be singular or a collection of objects.  So it's sound more like an Entity and a Model are more or less the same.  The Model is an all encompassing term, where an Entity is more specific.  A Value Object would be a Model as well.  At least in terms of MVC.  Maybe???</p>
  
  <p>So, in very rough terms, which is better?</p>
  
  <p>No "Model" really ...</p>
  
  <pre><code>class MyController {
      public function index() {
          $repo = new PostRepository();
          $posts = $repo-&gt;findAllByDateRange('within 30 days');
          foreach($posts as $post) {
              echo $post-&gt;Author;
          }
      }
  }
  </code></pre>
  
  <p>Or this, which has a Model as the DAO?</p>
  
  <pre><code>class MyController {
      public function index() {
          $model = new PostModel();
          // maybe this returns a PostRepository?
          $posts = $model-&gt;findAllByDateRange('within 30 days');
          while($posts-&gt;getNext()) {
              echo $posts-&gt;Post-&gt;Author;
          }
      }
  }
  </code></pre>
  
  <p>Both those examples didn't even do what I was describing above.  I'm clearly lost.  Any input?</p>