title: PHP Factory design pattern method clarification
body: <p>I want to know if <a href="http://www.phptherightway.com/pages/Design-Patterns.html#factory" rel="nofollow">this tutorial</a> is correctly implementing factory design pattern in PHP. Below is the actual source code.</p>
  
  <pre><code>&lt;?php
  class Automobile
  {
      private $vehicle_make;
      private $vehicle_model;
  
      public function __construct($make, $model)
      {
          $this-&gt;vehicle_make = $make;
          $this-&gt;vehicle_model = $model;
      }
  
      public function get_make_and_model()
      {
          return $this-&gt;vehicle_make . ' ' . $this-&gt;vehicle_model;
      }
  }
  
  class AutomobileFactory
  {
      public static function create($make, $model)
      {
          return new Automobile($make, $model);
      }
  }
  
  // have the factory create the Automobile object
  $veyron = AutomobileFactory::create('Bugatti', 'Veyron');
  
  print_r($veyron-&gt;get_make_and_model()); // outputs "Bugatti Veyron"
  </code></pre>
  
  <p>According to a book "Design Patterns" by <em>Gang of Four</em>, applicability of factory pattern is</p>
  
  <ul>
  <li>a class can't anticipate the class of objects it must create</li>
  <li>a class wants its subclasses to specify the objects it creates</li>
  <li>classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate</li>
  </ul>
  
  <p>First point, this example actually knows what class of objects to create, which is <code>Automobile</code>, doesn't it?</p>
  
  <p>Second point, there is no subclass. <code>Automobile</code> class does not inherit from <code>AutomobileFactory</code>. I thought AutomobileFactory should have at least one function implemented by Automobile, which deals with object creations.</p>
  
  <p>Can someone clarify this? I just started learning design patterns, and every time I encounter tutorials different from others, it confuses me a lot.</p>