I was updating the wikipedia's drupal page with pressflow distribution yesterday, there i observed that drupal is build using MVC design pattern [1]. But i remember my mentor telling me that drupal is NOT based on MVC. Is it changed in the recent version or the person who updated the wiki page has misunderstood the concept. Please enlighten me. Snapshot of the wiki page http://img101.imageshack.us/img101/4592/drupalmvc.png [1] http://en.wikipedia.org/wiki/Drupal#MVC_Framework -- Thanks Sivaji
Sivaji: Crell wrote about this a while back --> http://www.garfieldtech.com/blog/mvc- vs-pac That should help clear the air :) Best _Pavan On Friday 11 December 2009 18:27:03 sivaji j.g wrote:
I was updating the wikipedia's drupal page with pressflow distribution yesterday, there i observed that drupal is build using MVC design pattern [1]. But i remember my mentor telling me that drupal is NOT based on MVC. Is it changed in the recent version or the person who updated the wiki page has misunderstood the concept. Please enlighten me.
Snapshot of the wiki page http://img101.imageshack.us/img101/4592/drupalmvc.png
[1] http://en.wikipedia.org/wiki/Drupal#MVC_Framework
-- Thanks Sivaji
-- -Pavan K Murthy http://grahana.net/
The way the MVC term is used to describe various web (MVC) frameworks - yes. In fact I believe all of them squint to be able to see the MVC. If one wants to be really strict, in a design pattern lawyer kind of way - no. Drupal components are not designed with OO in mind, although there are clear parallels, and MVC is a pattern for OO design, speaking strictly, it makes no real sense outside OO designs. But put polarised glasses, and start lighting the source with various light sources, and behold various design patterns showing up. Subject-obesrver - hooks. Protocols - the hook instances. MVC or rather MVC adapted for the web - what Sun used to call model2, etc...
On Fri, Dec 11, 2009 at 1:57 PM, sivaji j.g <sivaji2009@gmail.com> wrote:
I was updating the wikipedia's drupal page with pressflow distribution yesterday, there i observed that drupal is build using MVC design pattern [1]. But i remember my mentor telling me that drupal is NOT based on MVC. Is it changed in the recent version or the person who updated the wiki page has misunderstood the concept. Please enlighten me.
In the very dumb way most people understand MVC, yes Drupal is MVC, because there is a separation between the presentation and content. But no, that's not strictly speaking MVC. Strict MVC doesn't exist for web application, because a big part of the view and the controller is actually handled by the browser. Damien Tournoud
On 2009-12-11, at 9:33 AM, Damien Tournoud wrote:
a big part of the view and the controller is actually handled by the browser.
This is true for how %99.9 percent of the Drupal installations out there, but a "view" doesn't have to be graphical. A View could be RSS, XML, Postscript, etc. IMO the $page array in D7 brings Drupal much closer to an MVC-like design, as you now have an abstracted representation of data before it's processed by the View (whatever your theme_* and .tpl.php files do). --Andrew
Andrew Berry wrote:
On 2009-12-11, at 9:33 AM, Damien Tournoud wrote:
a big part of the view and the controller is actually handled by the browser.
This is true for how %99.9 percent of the Drupal installations out there, but a "view" doesn't have to be graphical. A View could be RSS, XML, Postscript, etc. IMO the $page array in D7 brings Drupal much closer to an MVC-like design, as you now have an abstracted representation of data before it's processed by the View (whatever your theme_* and .tpl.php files do).
--Andrew
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
On Fri, 2009-12-11 at 10:40 -0600, larry@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.
Pierre, I think you are making a case that people are misusing the MVC name rather than including Drupal in the misuse. On Dec 11, 2009, at 11:03 AM, Pierre Rineau wrote:
On Fri, 2009-12-11 at 10:40 -0600, larry@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.
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@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.
Some time ago, I've given up on reading patterns literally. In my world they are there to highlight or sum up ideas, but have to be reinvented from basic principles every time, based on the current task constraints.
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.
Drupal does employ MVC. In its own reinterpretation, taking into account the realities of writing web applications in php, as seen originally in Antwerp. No it is not a mish-mash of patterns. There is no such thing. An arbitrary number of patterns and anti-patterns can be found in every moderately complex application. The precise number depends on the time of day, the reader and the squinting techniques used. For example, I could argue that Drupal implements the oldest 'pattern' of them all - the REPL for a stateful language from urls to pages, with an init, call^H^H^H^Hdispatch, load, ...., show pipeline... Actually, precisely the request processing pipeline of drupal is what makes it look like an MVC based framework - each different stage can fall into only one of the categories of MVC. http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html http://kasparov.skife.org/blog/src/java/mvc.html Sorry, can't help but feed the fire. It is cold outside. :)
Drupal IS totally MVC, if modules are well-coded. The fact is V (theme system) is well separated from M and C. C is the menu router (with hook menu) and M is the module implementation of doing things. Event during bootstrap, first menu router is called, then only after the end the theme renders the page (even if theme() functions are called all among the router callback lifetime, it uses the same theme as the page). Sometimes, rendering and data handling is really too tight, it really depends on the module code which we are talking about. This problem seems to be redondant in all frameworks. Pierre.
participants (9)
-
Alex Bronstein -
Andrew Berry -
Damien Tournoud -
larry@garfieldtech.com -
Matthew Farina -
Pavan Keshavamurthy -
Pierre Rineau -
sivaji j.g -
Vladimir Zlatanov