Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Model Glue Tips Part 6: Create a services directory to keep your model tidy

August 14, 2007 · 5 Comments

By default, when you create a Model-Glue project you get the following directories in you root project:
	/config
	/controller
	/css
	/images
	/model
	/views
This fits (apart from the css and images folders) with the idea of an MVC model. The problem that I find is that Reactor (by default) creates objects in the model/data directory. Why is this a problem you might ask? Well, I find that it doesn't fit in with what I think of the model. I see the model as the business model, and I tend to add another directory; "services" which interact with the model. The services are stored there and they glue the model together the model being stuff created by your ORM. I know people might disagree (no names) but I tend to add a services directory in which I have number of cfc's usually named %3CSomething%3EService.cfc . In my model folder I then have the objects and gateways. This means that the controller talks to the service and the service talks to the gateways and objects. This keeps it nice and tidy in my view. Of course, it doesn't matter at the end of the day, since you can change where all the objects are stored and just change your ColdSpring.xml file (you ARE using your ColdSpring.xml file your services aren't you?!)

Tags: model-glue

5 responses so far ↓

  • 1 Matt // Sep 22, 2008 at 4:13 PM

    I think it might help some people if you posted an example of a service you have written.
  • 2 Mark Drew // Sep 22, 2008 at 4:13 PM

    I have written many services in my time, but for example a PersonService might be something along the lines of:
    Person
    getPerson
    getPeople
    getActivePeople

    etc etc,
  • 3 Henry // Sep 22, 2008 at 4:13 PM

    I found that by putting DAO + Gateway + Bean + Service together has one advantage. They can refer to the bean without fully qualified name. Since Service will have a lot of method that takes a Bean in as a type, without fully qualified name, the service can be moved into another project without changing the fully qualified name in type.

    what do you think?
  • 4 Henry // Sep 22, 2008 at 4:13 PM

    oh, and have most methods having access = package.
  • 5 Mark Drew // Sep 22, 2008 at 4:13 PM

    @Henry: That is true, but one thing that I tend to do is set everything in ColdSpring, so the DAO + Gateway + Bean are refered to from Coldspring. But I think you have a valid point, and It just depends.

    My services tend to bring a lot of things together (People, Security etc) so its easier to have it access stuff from coldspring.

Leave a Comment