title: Prototype pattern vs creator delegate
body: <p>So I read about <a href="http://ralphschindler.com/2012/03/09/php-constructor-best-practices-and-the-prototype-pattern" rel="nofollow">prototype pattern</a> today and find that I actually came across this programming problem several times without realizing it myself.</p>
  
  <p>My understanding from having read that article and wikipedia seems to be:</p>
  
  <blockquote>
    <p>Use prototype pattern to clone an existing object then change its
    properties, instead of trying to create one from scratch when there is
    no way to know beforehand its constructor or what it will be.</p>
  </blockquote>
  
  <p>The way I usually solve this problem is to use a function delegate that returns the object:</p>
  
  <pre><code>// Pseudocode
  
  // Library Routine
  function GetTasks(CreateTaskDelegate callback) {
      var task = array();
      foreach(var rows as row) {
          tasks.push(callback($row));
      }
      return tasks;
  }
  
  // Library Interface / Abstract Class
  class Task { }
  
  // User Concrete Class
  class MyCustomTask extends Task {}
  
  
  // delegate "pattern"
  GetTasks(function($row) {
      return new MyCustomTask($row);
  });
  </code></pre>
  
  <p>How does this compare to the prototype pattern? It seems like the prototype pattern has a narrower applicable scope of usage, so what else is it good for?</p>