RE: [coldbox:7354] Re: Handler, Service, DAO question

The benefit of those layers is never really apparent in the simple examples. In fact, if that’s all your app is doing, I’d venture to say it is overkill. (Heresy, I know!)

I fought with the same issues myself when I first starting using beans, daos, and services. It just felt like a bunch of empty layers. It makes a lot better sense when your beans and services start filling with business logic and the separation is more apparent.

This is the way I see the breakdown and the benefit it gives:

  • DAO: store and retrieve data for a specific business entity, or a set of tightly coupled entities.
  • Bean: contains all logic and attributes DIRECTLY related to a specific business entity
  • Service: contains all logic for a set of inter-related business entities and handles their interactions together. Also CAN a good place to enforce security or persistence. Your services are the “gateway” to your models.
  • Controller: Directing the flow of the pages on your site and what data is coming in and out. Deciding what views to display, what layouts to use, etc. This is where it can be easy to stick business logic, but you shouldn’t. My test is that you should be able to do most everything the core of your app does (as far as loading, saving, and processing your models) with using nothing but the Services. The controller is just there to direct traffic.
    Anyway, that’s just my 2 cents based on my experiences. Other people might see the break down differently, but the main point is each layer has its own job and that job isn’t necessarily apparent (or necessary) unless your app is large enough to have some meat on it. Oh, and for the record, I’m for fat beans, thin services, and thinner controllers, but that’s really a matter of preference. :slight_smile:

Thanks!

~Brad

Thanks for the replies.

@Ernst - That is true, you could create one monolithic file, but I
think that comparison is a bit unrealistic compared to the comparison
of just eliminating your service layer and have your handler call your
DAO, but either way your point is well taken and I get the meaning.

@Brad - Thanks for the breakdown, what you've outlined makes sense. I
guess it's like art, you have to find the right mix and balance given
the requirements of the app. For simple apps it may overkill as
you've stated, and for more complex apps, the pattern may being to
show it powers.

I guess there is more than one way to skin a cat especially with CF

-West