[Catalyst] Best Practices Question: What to put in an ActionClass Versus a Custom Controller?

John Napiorkowski jjn1056 at yahoo.com
Wed Jan 17 00:40:31 GMT 2007


Hi,

I've been thinking a lot about all the different ways
Catalyst let's you do stuff and wondering what, if
any, thoughts any of you might have regarding some of
the overlapping features of Controllers and
ActionClasses, particularly when thinking about
creating good reusable code.

Before we had ActionClasses if you wanted to create
chunks of reusable logic, you created base Controllers
and inherited from them, or you inherited from other
standard Perl modules that were designed to work well
with controllers.  So all the glue logic was in the
controller.  Now with ActionClasses you have the
ability to create classes for logic that is outside of
the controller completely.  So this gives you two ways
to create reusable code.  So with ActionClasses your
Controllers start to look more like big configuration
files, in some ways.

Now, most of the examples in the tutorials show all
the glue and processing logic, like form processing,
inside the controllers; given this one could feel that
this is the Catalyst way.

>From looking at other MVC systems, like struts, you
tend to see nearly the opposite, one big controller
and lots of actions, at least in the examples I see in
the Struts tutorial.  My understanding of Jifty is
that it's similar, they have a module for mapping urls
to code.  Now, in Struts there is nothing stopping you
from creating more then one base controller, but it
seems like the controller is more of a big config
file.  In fact, the meat of struts is inside xml
config files.

Seems like in some ways that Catalyst is moving in
that direction.  Most of the Reaction examples I see
have the controllers mostly used for setting
configuration stuff, all the action takes place in the
action classes.

So given this I am wondering if we could establish
some best practices about when is it good to put that
glue logic in Controllers versus in an ActionClass. 
Here as some thoughts I came up with:

Controllers Good for:

-- Configuration (can put everything in the global
catalyst config.yml file)

-- mapping URLS to Code

-- containing methods and attributes of use during a
request.

ActionClasses Good for:

-- When you need to create custom url matches that
can't be handled by one of the exisintg Action
attributes such as Path, Regex, etc.

-- Encapsulating reused functionality, such as form
processing or accessing models.

If I follow these ideas then I find my code starts to
look a lot like the Java Struts examples I see around
a lot.  Is that good or bad do you think?  Am I
missing something great about using Controllers for
logic inheritance purposes over using ActionClasses?

Anyway, it was a long weekend in the USA and I haven't
been able to get my head back to work yet.  Just
wondering what your thought are.

--john


 
____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com



More information about the Catalyst mailing list