Version 2, last updated by Aric Caley at October 21, 2009 21:55 UTC

Naked Objects PHP

 

The primary goal is to unify the things that are common between the three typical layers of a web application.  These three layers, or tiers, are the HTML, the PHP objects, and the database.  At least, that is the most typical arrangement.  Really what we are talking about is the View (HTML), the Controller (PHP objects) and the Model (database).  Yes, thats the famous MVC you always hear about.

Usually, when you read about MVC, they talk about these three things being three different types of objects in your backend code.  In reality, the View object just generates the actual view (usualy HTML) and the Model just interfaces with the database.  In the original envisioning of MVC (I will leave it to you to google the inventor of MVC) the View was always intended to be an ephemeral, dynamicaly generated thing, not just some kind of glorified template; and the model wasn't just meant to be a one to one representation of some datastore, but more closer to what the end user imagined the data to be and then translated to whatever arcane internal datastore the programmer came up with.

This was more a conceptual separation than a practical one, designed to provide for more user friendly and flexible interfaces.  It has since become not much more than a practical separation purely to separate design concerns for the programmer.  The problem with this, is, that it sucks.. both for the programmer and for the user.

For the user, this doesn't do much at all to make things better.

For the programmer, it means extra work.

Which is where NOP comes into play.

For the programmer, you wind up doing a lot of the same things in different ways at each level.  For example, the most basic of things, the name of a piece of a data.  You need to have that name correct in the HTML, in the php code that processes it, and in the final database field it gets stored in.  Get one wrong and nothing works.  You can try to make things easier by making sure to use the same names throughout, but sometimes you can't.

Another good example is validating the data.  You probably want to validate in the HTML form for quick feedback to the user.  But for security reasons you want to validate again at the php level to prevent bad data coming into the script.  Finally, you may have to validate again before sending to the database just to make sure you dont send bad data into your tables and screwing things up.