Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are few thing that seem wrong in this case.</p> <p>First of all , there are two similar structures which are used for object creation:</p> <ul> <li>factories: if object requires some sort of initialization before released for 'consumption' </li> <li>builders: if before creating object you have to create bunch of other objects</li> </ul> <p>Usually people do not distinguish between the two, and just call them "Factories". So these would be two case where you use a factory.</p> <p>What you have right now does not fit the description. You are creating some sort of database connection, then getting some data, and then using it for creating a list of objects. This is not a reusable code.</p> <p>It would be much better if the usage of factory would be something like this :</p> <pre><code>$connection = new PDO( .. blah.. ); $stmt = $connection-&gt;query( 'SELECT * FROM '.$type.' LIMIT '.$count ); $factory = new Factory; $collection = $factory-&gt;buildCollection( $type, $stmt-&gt;fetchALL(PDO::FETCH_ASSOC) ); </code></pre> <p>Of course, with factory class which implements this behavior.</p> <p>Additionally , you might want to watch (assuming, that you haven't seen already) two videos on the subject: </p> <ul> <li><a href="http://www.youtube.com/watch?v=RlfLCWKxHJ0">Don't Look For Things!</a></li> <li><a href="http://www.youtube.com/watch?v=wEhu57pih5w">Unit Testing</a></li> <li><a href="http://www.youtube.com/watch?v=-FRm3VPhseI">Global State and Singletons</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload