Ogres Have Layers... Onions Have Layers...

I apologize for the obscure Shreck reference but that scene from the movie pops into my head every-time I start thinking about all of the different layers we code into our applications. I was thinking recently about how many different layers we use and I started to wonder, are we doing this because it truly makes our applications better or simply because we can?

As ColdFusion has progressed as a language, lots of these concepts have started to surface from other types of programming. Seven years ago, no-one was talking about building service layers and domain models in the ColdFusion community, we were so focused on frameworks and trying to increase code re-use. Now its not uncommon for an application to use a framework and MVC to separate the views from the model and use a controller to tie it all together, then throw in a service layer as your model which points to a data access layer and processing logic layer and, well you get the point.

I see the benefits of having layers within your application, dont get me wrong, but sometimes I feel like maybe we over do it. For instance, when I write Fusebox applications, I use MVC patterns and write all of my controllers in XML like a good little Fuseboxer, I use a custom lexicon to call my ColdSpring factory and get beans in those controllers which call my service layer objects. Now these service layer objects do not call the database directly, they call methods in the data access layer to actually handle that. My biggest question is why does the controller have to call a service layer when it can interact with the data access layer directly. cant the controller act as a service layer? Are there any benefits of using the service layer that outweigh all of the extra code in the layer that has to be maintained?

Now I know that there are no hard and fast rules when it comes to architecture. We are free to do things as we chose. I guess Im just playing devils advocate here more than anything really. Sometimes when we look at things in a totally different light, they become more clear.


There are no comments for this entry.

You may Leave a Comment