[development] is drupal a MVC stuff

Alex Bronstein alex at craftyspace.com
Fri Dec 11 18:20:21 UTC 2009


The problem with language in general, and domain-specific jargon 
especially, is that there are layered definitions for the same term. 
 From a very broad-stroke perspective only, one can call Drupal an MVC 
framework. From http://en.wikipedia.org/wiki/Model-view-controller:

------------------------
Model–View–Controller (MVC) is an architectural pattern used in software 
engineering. The pattern isolates business logic from input and 
presentation, permitting independent development, testing and 
maintenance of each.
...
MVC is often seen in web applications where the view is the HTML or 
XHTML generated by the app. The controller receives GET or POST input 
and decides what to do with it, handing over to domain objects (i.e. the 
model) that contain the business rules and know how to carry out 
specific tasks such as processing a new subscription.
...
In the design of web applications, MVC is implemented by web template 
systems as a "View for web" component.

MVC is typically implemented as a "Model 2" architecture in Sun 
parlance. Model 2 focuses on efficiently handling and dispatching full 
page form posts and reconstructing the full page via a front controller. 
Complex web applications continue to be more difficult to design than 
traditional applications because of this "full page" effect. More 
recently AJAX driven frameworks that focus on firing focused UI events 
at specific UI Components on the page are emerging. This is causing MVC 
to be revisited for web application development using traditional 
desktop programming techniques.
------------------------

As Pierre points out, Drupal (and especially Drupal 7) mostly follows 
all of this.

However, only if you lump "all the module code" into the "model", and 
ignore that a lot of modules implement their own sub-frameworks, 
complete with their own sub-controller and sub-view layers. That's why 
Larry correctly points out that Drupal is closer to PAC 
(http://en.wikipedia.org/wiki/Presentation-abstraction-control), but 
even that isn't strictly accurate.

Architecturally, Drupal core is a mish-mash of different patterns, some 
implemented consistently with the well-accepted rules of the pattern, 
some implemented inconsistently for no good reason, and some 
intentionally violating the rules for performance or some other valid 
reason. On top of that, Drupal is first and foremost a module-oriented 
framework, there are thousands of modules, and each one is free to use 
its own patterns, well or poorly depending on the module maintainer.

This makes it hard to explain what Drupal is with any single term like 
MVC. But that's not to say that Drupal isn't an awesome framework. While 
it can still be improved and simplified, and learn from the lessons of 
other frameworks, it's a very practical and powerful framework that 
allows modules to do just about anything, themes to control almost every 
aspect of the presentation, and includes some pretty powerful 
control-layer and utility tools in core.


Pierre Rineau wrote:
> On Fri, 2009-12-11 at 10:40 -0600, larry at garfieldtech.com wrote:
>   
>> The defining attribute of MVC is, IMO, that the View component has 
>> direct access to the Model component using an observer relationship, 
>> without going through a separate Controller.
>>
>> hook_page_alter() is in no way a direct observer relationship between 
>> the View component and the Model component.  *_alter hooks are a 
>> pipes-and-filter approach, or, arguably, visitor pattern.
>>
>> Drupal is very much not an MVC design.  It's not true PAC either, but I 
>> have and do argue that it is closer to PAC than MVC.
>>
>> Someone needs to correct the Wikipedia page, which is simply wrong in 
>> this regard.
>>
>> --Larry Garfield
>>     
>
> If you want to stick to strict MVC definition, yes Drupal is not, but in
> the most software I saw or developed with until now, not anyone had a
> real MVC implementation.
>
> In MVC, this Controller -> Model -> View (data flow)
> In Drupal, data flow is:
>  - Controller (menu router) -> Model (menu callback, module code)
> (direct association)
>  - Model (indirect association through the theme() calls) -> View
>  - View -> Controller (indirect association, through user clicks)
>
> This is an incomplete and simple (without the observer/observable
> pattern) implementation, but I think it does sticks to MVC pattern.
>
> This is an opinion, I think it can be discussed.
>
> Hook system is a different pattern used for different goals, mostly used
> to alter data (it does not alter the behavior I described upper, except
> maybe in some really weird cases).
>
> Pierre.
>
>
> Event if observer pattern is not really here, I think it sticks to MVC
> pattern.
>
>   



More information about the development mailing list