[Catalyst] Controllers vs Models

Perrin Harkins perrin at elem.com
Thu Jun 2 18:57:58 CEST 2005


On Thu, 2005-06-02 at 11:47 -0400, David Storrs wrote:
> What do the rest of you see as the dividing line between a  
> Catalyst::Model and a Catalyst::Controller object?  When you are  
> creating a new object, how do you decide which hierarchy it belongs in?

This division in web-based MVC development is frequently a subject of
debate.  Most tools break it down in the simplest way, where the model
is essentially just the database access objects.  MVC purists complain
that this causes a lot of logic to end up in the controller, which was
supposed to be nothing more than translating HTTP to method calls (i.e.
the controller should not need to know about your problem domain).  The
usual fix suggested is to make what are sometimes called "action
classes" which contain the logic you would otherwise put in a controller
but are part of the model instead.  The action classes are coded to be
independent of the web environment so they can be used elsewhere.

As an example, for a restaurant reservation system you might have
classes representing tables and people, and action classes for things
like finding a free table, booking a reservation, etc.  These make sense
for situations where they need to act on multiple database objects in a
complex way.

The problem with this approach is that it becomes very annoying when
working on simple actions, especially the kind of CRUD stuff that
Catalyst and Maypole have done a good of automating.  But maybe you can
just call the CRUD automation "action classes" and go to bed early...

I plan to touch on this in my talk at YAPC in Toronto about MVC
frameworks, but probably won't have enough time to go into it deeply.

- Perrin




More information about the Catalyst mailing list