Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC/HMVC and Object Oriented programming
    primarykey
    data
    text
    <p>I've been reading and learning about Object-Oriented programming (<a href="http://rads.stackoverflow.com/amzn/click/0596008678" rel="nofollow noreferrer">Head First Object-Oriented Analysis and Design</a> and <a href="http://rads.stackoverflow.com/amzn/click/0735619670" rel="nofollow noreferrer">Code Complete: A Practical Handbook of Software Construction</a> – thanks to suggestions found on StackOverflow). I've also been learning how to use a couple PHP MVC frameworks (specifically <a href="http://codeigniter.com/" rel="nofollow noreferrer">Codeigniter</a> and <a href="http://kohanaframework.org/" rel="nofollow noreferrer">Kohana</a>).</p> <p>Some of the principals of Object-Oriented that I've read about are handled differently by the MVC frameworks. I think I've managed to understand the differences and why the decisions were made (complete and easy to use solution), but I wanted to test my assumptions...so if you'll humour me...please comment or correct.</p> <p><strong>Assumption #1:</strong></p> <p>Thinking about the right abstraction for a web application, the directory containing the library of classes should be located outside of the directory containing the presentation files. This organization adheres to the DRY ("Don't Repeat Yourself") principal allowing for multiple presentation folders (www.domain.com, management.domain.com, api.domain.com, etc.) to work with the same objects.</p> <p><strong>Assumption #2:</strong></p> <p>If all your classes are located outside of your presentation folders, then the models in your MVC implementation just use instances of those classes. If that's true, then the MVC framework is just a presentation class (the controller) that helps to manage the input (GET &amp; POST requests), the response (models or instances) and output (views or templates).</p> <p><strong>Assumption #3:</strong></p> <p>If the MVC framework is just a presentation class, then the database class that the controller instance initializes breaks the abstraction of the controller class. A model (of the controller instance) shouldn't have a ("has a") database, it should have a thing (user, product) from the library of classes and that thing should have a database.</p> <p><strong>Assumption #4:</strong></p> <p>Furthermore, if the MVC framework is just a presentation class, the database class that the controller instance initializes is too tightly coupled with the controller class. Changing from one method of storage to another requires re-factoring of all the models.</p> <p><strong>Assumption #5:</strong></p> <p>With a HMVC framework, the issues with the controller containing the database is worse, because your models are more module (more models, more re-factoring).</p> <p><strong>UPDATE:</strong></p> <p>Sorry, I may have used the terms controller and model a little loosely...maybe that speaks to the tight coupling. The source of my confusion stems from the <a href="http://codeigniter.com/user_guide/database/examples.html" rel="nofollow noreferrer">database class syntax</a>.</p> <p>With a model, shouldn't it be:</p> <pre><code>$user = new User($id); $data['name'] = $user-&gt;getName(); $data['title'] = $user-&gt;getTitle(); return $data </code></pre> <p>Instead of:</p> <pre><code>$query = $this-&gt;db-&gt;get_where('user', array('id' =&gt; $id), 1, 0); $row = $query-&gt;row_array(); $data['name'] = $row['name']; $data['title'] = $row['title']; return $data </code></pre>
    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