Handler, Service, DAO question

Hi,

I just wanted to see if what I'm using is dated or if there is a
cleaner way to do what I'm doing. For example, take the concept of a
user registering on a website.

1. User submits registration data on form

2. Coldbox event handler receives request

3. I'm currently creating an empty RegistrationBean ( I guess like a
value object?? )

4. Populate it using registrationBean.setEmail( rc.email ),
registrationBean.setPassword( rc.password )

5. Call the beans validate method to validate the data, send back to
client if there's a problem, otherwise continue.

6. Event handler has an instance of my Account Service and in my
handler I call
"instance.AccountService.RegisterUser( registrationBean ), passing in
the Registration Bean to the service layer

7. Service layer looks like:

<cffunction name="RegisterUser" access="public" returntype="void">
    <cfargument name="registrationBean" type="component"
required="true" hint="The Populated Bean" />
    <cfset var result = "" />
    <cfset result =
instance.AccountDAO.RegisterUser( arguments.registrationBean ) />
  </cffunction>

8. The DAO has a stored procedure call that inserts the data and
returns the id of the newly inserted record

I'm wondering what the problem would be if I just called the DAO
directly as opposed to having this intermediary Service layer that is
just handing off the data to the DAO. Can someone shed some light on
this?

Thanks,

-West

One of the goals of a service layer is to protect your application from
change. What if later on you stopped using the DAO and used ORM, etc.
By keeping the service layer, you would only have to make the change
from the DAO to ORM in one spot, increasing your codes maintainability.

Does that make sense.

Curt Gratz
Computer Know How

That is true, but I guess I'm questioning the need for the handler,
service, and DAO vs. just a handler and a DAO.

With a handler and only a DAO I will only have to change it in one
place also. I'm not suggesting that eliminating the service layer is
better, I'm just trying to see if there is any reason to keep it and
not just have my handler interact with my DAO. For years I've used
this handler/service/DAO approach but wanted to see what others may be
doing.

West,

You could also create one cfm file without MVC framework at all.
It's just a best practise approach to use views controllers and services.
So your controller asks your servicelayer: "Please give me a object
which I e.g. will populate and then I will return it, so you can store
it".

Ernst