Note that there are some explanatory texts on larger screens.

plurals
  1. POAm I writing procedural code with objects or OOP?
    primarykey
    data
    text
    <p>So basically I'm making a leap from procedural coding to OOP. I'm trying to implement the principles of OOP but I have a nagging feeling I'm actually just writing procedural style with Objects.</p> <p>So say I have a list of pipes/chairs/printers/whatever, they are all all listed as products in my single table database. I need to build a webapp that displays the whole list and items depending on their type, emphasis is on 'correct' use of OOP and its paradigm.</p> <p>Is there anything wrong about just doing it like:</p> <blockquote> <pre><code> CLass Show { public function showALL(){ $prep = "SELECT * FROM myProducts"; $q = $this-&gt;db-&gt; prepare($prep); $q-&gt;execute(); while ($row = $q-&gt;fetch()) { echo "bla bla bla some arranged display".$row['something'] } } </code></pre> </blockquote> <p>and then simply </p> <pre><code>$sth = new show(); $sth-&gt;showAll(); </code></pre> <p>I would also implement more specific display methods like:</p> <p>showSpecificProduct($id)->($id would be passed trough $_GET when user say clicks on one of the links and we would have seperate product.php file that would basically just contain</p> <pre><code>include('show.class.php'); $sth = new show(); $sth-&gt;showSpecificProduct($id); </code></pre> <p>showSpecificProduct() would be doing both select query and outputing html for display.</p> <p>So to cut it short, am I going about it allright or I'm just doing procedural coding with classes and objects. Also any ideas/hints etc. on resolving it if I'm doing it wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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