On Wed, Jun 11, 2008 at 3:14 PM, Ben Bangert <[EMAIL PROTECTED]> wrote: > On Jun 11, 2008, at 1:10 PM, Karlo Lozovina wrote: > >> What's the practical difference between controller based approach and >> views based one? Eg. Django views, and controllers in Pylons? It >> doesn't seem that much different, so why not make all controller >> actions regular functions, instead of class methods? What's the gain >> in this controller approach, if any? :) > > Terminology really. Note that webapps in general are only vaguely mapped to > the entire MVC concept in that you have a model representing domain logic > (generally with a database), a controller that gets the request and decides > how to respond, and a view (template) which the controller uses to create > the response with the data (Model). > > So Django is more-or-less MVC, they just call it MTV (Model-Template-View), > and their 'View' is doing the logic with the request, fetching data from the > Model, and using a template (aka, view), to return a response. By any > definition of MVC I've seen, Django is without a doubt MVC as well: > http://en.wikipedia.org/wiki/Model-view-controller > > They've provided a reason for why they choose to call it MTV on their FAQ > page, which differs from every other web frameworks rather unanimous > interpretation of it, and so far has led to more than a little confusion > when I've seen Django users using other MVC frameworks and frequently asking > about 'views' when people understand that to be 'controllers'. > > Regarding the use of a class vs a function for the controller, there are > some advantages with the class. You can easily have stuff done before any of > the methods are called for example, and you can set things on the class > object and have helper function utilized that have access to them on 'self' > as well. Also, you can develop mix-in style classes, to easily add generic > methods to various controllers merely by changing the inheritance.
MVC is a cargo cult ;) http://jjinux.blogspot.com/2005/04/mvc-cargo-cult.html I agree with Ben. Having classes with methods has all sorts of OO benefits. Consider, you can implement __getattr__ and do all sorts of cool tricks. It's also nice to share a bunch of code and data via self. If you don't use classes, you're forced to do everything with function decorators. -jj -- I, for one, welcome our new Facebook overlords! http://jjinux.blogspot.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---