Title: Message
Hi Nando,
 
Agreed 100% with everything except for the idea that having a facade to the model creates spaghetti code.
 
There are two distinct functions the controller usually handles in an HTML app - all the HTML specific stuff, and orchestration. If you have only one controller layer that always calls functions to get session information, check for cookies and the like, try calling that using a web service or flash remoting and see what happens. Of course, you could replicate your orchestration code in the flash movie and in your HTML controller and have flash access your model directly, but then if your business rules for orchestration changes, you have to change them in two places.
 
To me, it just makes perfect sense to have a facade to handle orchestration and to have a seperate controller to handle all of the HTML specific stuff if you're ever going to expose your business methods to non-HTML consumers. And it's not like this is a pattern or approach I made up out of thin air - I'd say it's a pretty well established pattern for enterprise architecture.
 
While you're pointing to resources, I'd also add Martin Fowler for some less CF specific, but interesting articles.
 
Best Wishes,
Peter
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nando
Sent: Saturday, June 10, 2006 12:03 AM
To: CFCDev@cfczone.org
Subject: Re: [CFCDev] Do I Really Need A Controller?

Ummm ... something to say here.

What you'll *always* need, no matter how you break your code apart, is some bit of code that tells the other bits what to do and when to do it.

Now, you can spread that out all over the place, CodeChunkA tells CodeChunkB to do something and then CodeChunkB tells CodeChunkC and CodeChunkD to do something, and then CodeChunkA tells CodeChunkE and F to do something and so on until you get to CodeChunkZCZR ... but then when you or someone else comes along in 5 or 6 months and looks at that, they'll have a really hard time figuring out how it all works.

Coding in this style has come to be known in some circles as "pasta" of the long stringy kind. Spaghetti. It's a very Italian way of dealing with things. Everybody tells everybody else what to do. (Ciao Massimo, just joking a little! Don't take me seriously ;-)

So in the example above, we don't have a single (or several) well defined controller(s), but we still have chunks of code telling other chunks of code what to do and when to do it.

So ... you always need that "hey you, do this" stuff in your code. The only question is if you encapsulate it in one place, or spread it all around.

Many programmers, even Italian ones, seem to feel after a few years of experimentation that they are much better off encapsulating that necessary "hey you, do this" stuff in one place in their code, so they can easily come back to it down the line and see fairly quickly how the whole thing works.

So no, you don't need *A Controller*, but you will always need chunks of code telling other chunks of code what to do.

Nando :)

PS ... A good way to understand how a controller works is to take a good look at model glue. The controller is implemented in a very simple and straightforward way as ModelGlue.xml and the controller cfc's. I don't think many of us on this list would be able to implement a decent MVC app from scratch without a framework to guide us. So i wouldn't start there, unless you are very gifted at implementing abstract ideas in code from scratch.

I have a friend who teaches artistic painting classes. He always has someone in the class who comes up to him and tells him they're having trouble coming up with something to paint. So he tells them, always, "Relax, Just copy what i'm doing." And he turns the painting he's working on and points at it with a smile so the student has a good view of it.

The student goes back and starts copying. But the funny thing is, my painter friend tells me with a big grin on his knowing face, "they always paint something totally unique."

The only trick out here is to choose carefully who you "copy" from! Here's a short list from this copy cat:

Hal Helms (his newsletters)
Joe Reinhart (his tutorials but you have to search his blog for them, the arf framework, the model glue framework)
Sean Corfeld (his sample apps)
Ben Edwards (the machII framework)

Once you've been copying for awhile, if you're gifted, you might graduate to being an originator. But don't worry if it takes you a little while to get there. :)

Peter Bell wrote:
Yep. Controller is indeed traffic cop. Also, if there is EVER any chance of
a non-HTML interface to your site  (web services, flash remoting, whatever),
you will want two elements to the controller. A "framework" piece will
handle the junk you need to handle to read and speak HTML with a web browser
and the "orchestration" piece will call the right model methods in the right
order based upon business rules in a way that does not assume there is a
HTML request (think sessions, cookies, form variables, URL variables, HTML
as part of the response messages, etc.).

Best Wishes,
Peter

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf
Of Aaron Roberson
Sent: Friday, June 09, 2006 3:19 PM
To: CFCDev@cfczone.org
Subject: Re: [CFCDev] Do I Really Need A Controller?


So, you are saying that I should submit my form to the controller, and then
the controller will run the email evaluation and send an error if not valid,
or pass the form structure to the service to be inserted in the database if
the email is valid. Is that correct?

>From what I gather from your example, I think I am beginning to see how the
"traffic cop" works...

-Aaron

On 6/9/06, Dustin Tinney <[EMAIL PROTECTED]> wrote:
  
In that case my controller would have somethign like this...

if(NOT hasValidFields(attributes.form))
{
redirectToErrorPage();
}

model.storeInformation(attributes.form);
sendConfirm(attributes.form.email);

On 6/9/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
    
I just send a confirmation email, I don't really want to test the 
visitor to see how badly they want my newsletter... ha, ha.

-Aaron

On 6/9/06, Dustin Tinney <[EMAIL PROTECTED]> wrote:
      
Do you send your user a "verify" email or a "thanks for 
subscribing email"?

On 6/9/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
        
I have an email subscription form on my website that visitors 
can fill out and subscribe to our newsletter. I have created a 
subscriberBean.cfc with getters/setters and an email validation 
method, a subscriberDAO.cfc with CRUD methods, and a service 
that creates a DAO object and a gateway object and passes 
arguments to the DAO and the gateway (this is all based on Matt 
Woodwards
CF.Objective() example and Peter Farrell's code examples from
          
CFWeekly
  
1.10).

It seems to me like the view would interact with the service, 
which would perform my CRUD operations and return my the query 
results from my gateway. If so, what do I need a controller for? 
I've heard that controllers act as traffic cops, but I'm not 
sure what that means. If my view is validating form field 
entries, and my model is validating form field entries, and my 
view is getting everything it needs from the service layer, what 
do I need a "traffic cop" for?

Thanks for your feedback and suggestions!

-Aaron

On 6/9/06, Dustin Tinney <[EMAIL PROTECTED]> wrote:
          
Yes would be the answer to your question about needing a 
Controller. However with out knowing what your doing a little 
more It's hard to give direct examples of WHY you need it.

On 6/9/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
            
I have been plunging head first in to OOP (into a wall, I 
should
say...) and I am trying to put all the pieces together so that I
              
can
  
begin implementation.

Anyways, I am wondering if I need a controller layer in my 
design pattern? I really don't like the idea of using a 
configuration file (xml or index.cfm) and wiring everything 
to it like a fusebox, so I am staying away from frameworks. 
I have been learning about seperating my business model into 
beans, DAO's, gateways and services and I think I like the 
abstraction that offers. However, it seems to me like my 
views can interact directly with the service, making a 
controller layer unneccesary. Is that correct, or am I lost 
again?

P.S. I don't entirely understand what all a service does, so 
I do have some questions about the service layer, but I will 
start a seperate thread for that. I would have some 
questions about the facade layer, but I don't have a clue 
how to use that so I don't even know where to begin with the 
questions regarding that.

Thanks,
Aaron


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email 
to cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as 
the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by 
CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



              
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the 
subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by 
CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



            
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the 
subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by 
CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



          
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the 
subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by 
CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



        
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the 
subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by 
CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



      
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject 
of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/cfcdev@cfczone.org



    


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/cfcdev@cfczone.org





----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/cfcdev@cfczone.org



  


--


Aria Media Sagl
CP 234
6934 Bioggio
Switzerland
www.aria-media.com


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to cfcdev@cfczone.org with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

An archive of the CFCDev list is available at www.mail-archive.com/cfcdev@cfczone.org

Reply via email to