Orange is my favorite color

The last two days have been more thought-provoking than code-producing. Based on this thread on the model-glue list, I’ve been evaluating my service layer and whether or not I have an anemic domain model. I think I have the cooties. But I also have to push on so I’m going to correct it piecemeal. More on that later.

First, a big shout out to Mark Mandel of Transfer for spending about 45 minutes with me debugging an error I was receiving in Transfer. He also helped me work through some advanced Transfer functionality this afternoon. Thanks!

Findings Today

  1. IDs in Transfer must be unique – When Mark’s documentation says that any bean <id> must be unique, he MEANS it. I was plodding along, minding my own business when my code suddenly failed with this error:
    ATTRIBUTE NAME DOES NOT EXIST IN XOBJECT.XMLATTRIBUTES
    /transfer/com/object/ObjectDAO.cfc: line 81

    Then all of a sudden my unit tests failed too. Yikes! We debugged for a half an hour or so until Mark thought of checking whether or not I had more than one record with the same ID in that table. Sure enough, a failed unit test had left a record in the DB and it was missing a unique index allowing it to happen. Bollocks! Delete the extra record, put the key on, and all is well now.

    Take-away? Make sure you have a unique index for any field referenced as an ID in your Transfer.xml.

  2. Event naming – I think I’ve resolved my event naming scheme. I care about this a lot because I’m converting an existing app which means, very quickly, I’m going to have a few hundred events. I won’t have much time to learn what works for me before it’s live and I want to try and avoid changing the public events once launched.

    Here’s my plan:
    event - the default "public" event for a page or action. This will redirect to the appropriate "real" action like edit, or list, or so forth
    event.edit - the edit page (uses a view named frm.<something>.cfm)
    event.do - handles the form submit from event.edit; drives results based on results like isSuccess and isError to redirect to .ok and .fail respectively. I almost always use redirect="true" on success to prevent repeat submits.
    event.ok - the success message, if needed. Many times I just redirect to the default public event
    event.fail - the error message, if needed. Many times I just redirect to the .edit event
    event.list - if it's a master-detail type of interaction, the .list will list all of the options
    event.view - if master-detail, this will display a single option
    event.delete - for deleting a record

    There are cases where this won’t work of course but for the vast majority of CRUD operations, I think this gives me a repeatable and easy-to-follow set of events. I can imagine creating “sub” events for dealing with one-of-many scenarios like:

    clubs.list
    clubs.club.(edit|do|ok|fail|view|delete)

    I am testing this out now to see how it “feels”.

  3. Fat Beans – The beans I created for my API are, by and large, just value holders. The service layer is doing all the work. This is known as an anemic domain model. Many wise people recommend building smarter, more capable beans that can do more for themselves. I’m trying this approach with my member bean.
  4. Injecting Services into Transfer Decorator Objects – based on the Fat Beans thread, I wanted to try accessing my service layer from my member bean. But how? Coldspring can’t autowire these transient objects. Turns out Transfer has a bridge for Coldspring to make it happen. Mark has written some partial examples that I didn’t quite follow. We worked it out over IRC so I have posted a step-by-step here for those of us still on the learning curve.

Questions Today

  1. Tedious – Is there any way to make this go faster? Dealing with so many files (model-glue.xml, coldspring.xml, transfer.xml, a controller, a service layer, a bean and several views for everything makes developing more about hopping from file to file than coding. I find it very hard to “get in the flow”.
  2. CFEclipse Frustrations – I spent most of the morning trying to find how to automate some common code with snippets and shortcuts. I want to make some shortcuts out of snippet code but I can’t find a way to edit the actual code generated from a shortcut key (like ctrl-shift-D for cfdump). I’d like to add my own of these as using the mouse to click on a snippet is not how I work and keyboard shortcuts for snippets is somehow “not possible” (but Eclipse Monkey can do it?)

Resources Today

4 Comments

  1. Brian Rinaldi said:

    on January 10, 2008 at 6:01 am

    Yeah, it could go faster. How about using my Illudium PU-36 Code Generator to generate your Transfer XML, ColdSpring XML, decorators, gateways and so on.

  2. brian said:

    on January 10, 2008 at 9:35 am

    @Brian R – actually I have used the Illudium generator! In fact, I posted templates for Postgres some time back on my blog and might have sent them to you. I have my entire API converted, largely using your tool, however the tedious part right now is the model-glue.xml, controller setup, and view creation. I’m converting an existing app and I just thought it would go faster but there is a learning curve to contend with.

    However, I tried cutting and pasting my event naming scheme as a block last night to quickly set up a full CRUD scenario and it went very quickly so I’m feeling like I’ve got some momentum now. Which is good… because I only have 25 days until the conference. :)

  3. brian said:

    on January 10, 2008 at 9:36 am

    FYI, here is the post: http://www.ghidinelli.com/2007/07/18/postgresql-adapter-for-illudium-pu-36-code-generator/

  4. Brian Rinaldi said:

    on January 10, 2008 at 10:06 am

    Right! Duh! I know that post and even commented on it. In fact the adapter is in the SVN version, I just never got around to making a build. Ok. Pretend my comment was intended for your readers and not you and I can do a Pee Wee and say “I meant to do that”.

{ RSS feed for comments on this post}