(Consider hiring Doug to instruct you and your team in the ways of OO!)
I've been hearing the term 'Service Layer' everywhere for at least the past year and a half, as I'm sure most of my peers have as well. Whether it's seen in blog posts, heard during casual conversation at conferences, found in articles, or woven throughout almost any discussion at all concerning OO and Coldfusion...the term is quite prevalent and common these days. But I had a problem: the term held absolutely ZERO connotation in my mind. No picture was ever conjured up when I came across it, no corresponding 'Doug Boude' translation was found in my internal lexicon; I felt quite out of the loop. Ah, but recently that has all changed, as the phrase itself has not only come to life for me, but found an absolute and permanent place in all that I do, technically speaking; an epiphany, if you will. I just figured there were others out there who, like myself, may still be kinda grasping for a way to think about the term, so what follows is my personal definition/explanation of what a Service Layer really is. Please feel free to append, addend, flip, and twist it to your heart's content until it's as whole as it ever can be.
SERVICE LAYER
This is not NEARLY as gray and ambiguous a term as you might think. Picture if you will, a man sitting comfortably on his sofa. In one hand is the remote for his very large plasma TV; in the other hand is a remote for his home theater system. The two remotes and the man are all objects, and all three come pre-built with things they can do. In the kitchen is the man’s wife; let’s think of her as the calling application. She barks out the order to the husband object, “START THE MOVIE, YOU IMBECILE!”. The husband object just happens to have a startTheMovie method, and begins to execute it. First, he manipulates the objTVRemote object, calling its “tvOn” method. Then, he manipulates the objDVDRemote object, calling it’s “dvdOn” and “dvdPlay” methods. Now he manipulates the objTVRemote again, calling the “inputSRC” method and switching the tv to receive the dvd input. Tada! Movie is playing now!
Pretty clear scenario, eh? Well, in this illustration, the
Doug out.
You are not logged in, so your subscription status for this entry is unknown. You can login or register here.
Them: "SELECT * FROM Cust".
Me: You may WANT a list of all customers, but this is the list that I'm going to GIVE you:
SELECT * FROM Cust
INNER JOIN Security
ON Security.CustID=Cust.CustID
WHERE UsrID=#You#
Actually, no, a service layer is not an object factory at all...two different animals. An object factory is itself and object whose job it is to create instances of other objects for you. So, instead of writing 'createObject("component","model.user")', you'd instead ask your object factory for it with something like 'cfset myNewUserObj = objFactory(objToMake="user") . Make sense?
Why would you want to do this, you might ask? Well, you might want to do this in order to simplify your object creation process and lessen the amount of code needed throughout the rest of your app. There are a myriad of other possible reasons to do it, as well, but that's content for a blog post all its own.
Hope this helps some.
We build an app that manages medical benefits. In order to perform a simple task such as "change my medical coverage", there are actually several underlying object calls needed, and thus a "benefitServiceLayer" object. Now our home office mentions during a status meeting that they'd like to be able to leverage that same business logic in an app they're building, and they'd like to do it via web services. The only object that needs exposing as a web service is our benefitServiceLayer object...all of the other objects live below that one and are not accessed directly from the home office. So, from this scenario, it's absolutely clear that our service layer objects are JUST as much a part of our 'domain' as any other object containing business logic, and thus the service layer objects must belong within our MODEL directory.
That's what it looks like from where I'm standing, anyway.

