MVCR pattern (was Re: [Catalyst] Bing!)

John Siracusa siracusa at mindspring.com
Thu Aug 11 15:43:02 CEST 2005


On 8/11/05 9:15 AM, David Storrs wrote:
> On Aug 11, 2005, at 3:44 AM, Zbigniew Lukasiak wrote:
>> Perhaps we don't need to define it and use the practical distinction -
>> everything that you need to call outside of the web environment (from
>> crontabs etc) should go into the Model.
> 
> Or, perhaps we shouldn't.  A very good case can be made for the idea
> that the Model should be just a thin wrapper over the DB and that the
> Controller (notice the name) should be the 'smart' thing in the
> system.  Not everyone will agree with this view and it isn't the
> classical MVC view but neither of those things makes it wrong.

IME, tying any "base functionality" to your webapp is a mistake.  Take an
online store, for example.  Consider these functions: logging in, adding an
item to the cart, deleting an item form the card, updating quantities in the
cart, adding a credit card, making a purchase, charging the credit card,
producing a receipt, logging out.  All of these functions should be in
modules that have no ties whatsoever to the web or a webapp.

What the webapp should do is provide a UI for these functions, and add any
business rules that may vary.  For example, while the underlying module may
allow any receipt to be viewed, the webapp would enforce a constraint that
only allows users to view their own receipts.

This separation of the base functionality into generic modules is important
because there are almost always multiple interfaces to the same
functionality.  For example, the store administration and customer support
tools want to look at everyone's transactions, account info, and receipts.
Another example: batch jobs running via cron might want to empty or delete
carts that haven't been used in a while.

All of these "applications" should use the same set of base modules to do
their actual work, while providing their own additional constraints as
appropriate.  If you tie any of this functionality to a webapp (i.e., by
putting it in a "controller"), you will regret it as you are forced to
duplicate the functionality elsewhere.

-John





More information about the Catalyst mailing list