MVC: It's all about the data model!

Posted on Thu 22 December 2005 in misc

Harry Fuecks made some interesting observations on the Model-View-Controller (MVC) pattern of application development as it applies to Web applications in a very long post called MVC and web apps: oil and water:

What I'm really trying to say here is I think the desire for MVC on the server side is a result of obsessions with forms, limitations of Javascript, the desire to compete with desktop apps and that form method="DELETE" never happened (so it was necessary to bundle this as another action via POST the action).

Davey responded with Why MVC works for Web Applications, in which he wrote:

Adding support for these [new views, such as SOAP2] should not impact any other "View" of your application)

Hallelujah, brother!

And adding support for a different database (or flat file, or XML repository) in the "Model" layer of your application should not impact any "View" either... that turned out to be the central message in my presentation at php|works 2005. The message emerged as I was putting the presentation together, it wasn't what I had originally planned. But, when you look at the effort required to port an application to a different database... the value of separating your data model in any significant application becomes very apparent.

Quick and dirty apps that thoroughly mix SQL and presentation do have their place, but if you ever want to take advantage of a different database's features (ability to scale, or alternative licensing / support offerings, or integration with a third-party application, or whatever), MVC makes a whole lot of sense. Well, at least thoroughly separating your data model from the rest of your application makes sense.

PHP