[development] Data API

Larry Garfield larry at garfieldtech.com
Sun Sep 3 17:16:47 UTC 2006


On Sunday 03 September 2006 08:40, Frando (Franz Heinzmann) wrote:

> I've to say Mark's ideas are quite similar to something I thaught about
> sometimes. Recently, I realized a project based on CakePHP [1], a
> RoR-style MVC framework written in PHP. And I was just amazed how quick,
> clean and easy it is to realize what you want to have by using it. It
> would be great to have some more of the easy and simple way of
> development that comes with a good and well-done implentation of the MVC
> concepts. I'm not at all one of these guys who praise the MVC pattern as
> The One Way Of Web Development or The New Holy Grail, but my experiences
>   with CakePHP showed, that, if it's done in a good way, the MVC pattern
> is a robust, solid and rapid way of web development that can simplify
> web development in a good way.

Excuse me a moment while I get somewhat academically pedantic, but believe me 
there is a point to the following. :-)

MVC is a terrible pattern for web apps.  MVC really isn't possible for web 
apps.  I've seen only one architecture that tried to do actual MVC for a web 
app, and it's a complete and total disaster.

Why then do people always talk about MVC as the bees knees?  Because what 
they're calling MVC isn't; it's a bastardized MVC/PAC hybrid.  

MVC involves three distinct components: A data Model, a View component, and a 
Controller component.  The Model abstracts the data model of the system, the 
View component is the UI, and the Controller is an intermediary.  

OK, no big deal, we all know that; but there's an important detail that many 
forget: The View is the entirety of the connection to the outside world.  The 
View is both input and output into the system, and therefore must be an 
active component.  The user changes something in the state of the View.  The 
Controller, which is observing (Observer pattern) the View, notices the 
change.  It responds by (possibly) taking some action against the Model, 
which only the Controller can change.  The Model is then updated, and the 
View, which is in turn observing the Model, notices the change and makes 
read-only calls against it to update its own display.  

Why does this not work for web apps?  Because the browser (view) is stateless.  
You can't run an active observer over an HTTP connection.  If you're doing 
heavy Ajax then you can do the read-only calls against the model, but you 
still need to notify the Controller of changes actively, in a second HTTP 
call.  That's wasteful.

Drupal doesn't do MVC currently.  If it did, theme functions would be full of 
database calls, when that is actively discouraged. :-)

What Drupal does currently, and what makes much more sense in a web app, is 
PAC, Presentation-Abstraction-Control.  In PAC, input comes in via the 
Control component.  Control then reads and writes data to the Abstraction 
(data model), decides what to do, and sends raw data to the Presentation 
component, which in turn renders and outputs it.  A given PAC combination, or 
agent, can be paired with another or even daisy chained in parallel or 
sequence to do all kinds of funky things.  But the input always comes in the 
Control and output goes out through the Presentation.  

Drupal's menu system is its Control component.  The theme system is the 
Presentation component.  The node system is the Abstraction component.  
Separate PAC agents aren't really separated out, but they do map rather 
nicely to the block concept; each block built by a separate agent.  We kinda 
sorta do that now, but not formalized.

So I'm all for clean separation of system components in Drupal, really.  But 
let's keep in mind how we're doing it, and what the limitations are of a 
web-based system.  MVC is the buzzword for web apps only because Sun Java 
engineers thought it was cool, not because it actually fits well. :-)

Yes, it's a pedantic point, but it always bothers me when people talk about 
web apps as MVC, when in fact they simply cannot be by nature. :-)

</rant>

-- 
Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson


More information about the development mailing list