You ever had one of those 'light-bulb' moments?  I love when those come along because it usually means that something 'clicks' that I've been noodling on.  Today was one of those days.

The last 3 weeks, I have been working on converting a small content management application from 'spaghetti code' to a Mach II application.  The things that I've learned just in that endeavor are amazing.  As pretty much any developer will tell you, there's always a way that something could have been done "better". But I've decided that I really don't want to build any more applications without some sort of framework.

One of the concepts I've been interested in lately is the concept of using a service layer in your application.  The idea sounds great and reasonable on paper, but I've found it hard to figure out exactly how best to do that when coding--until now.  The concept really clicked home with me when I began creating a *very* small Flex application for one of the more intricate CRUD functions in the aforementioned application.  I figured out that I had been thinking of the service layer at the wrong point in the "stack".  For some reason I had in my head that your service layer was actually one step higher in your application stack than your controllers.  Obviously that's not the case as I found out when I started trying to figure out how to leverage the code I had written for the Mach II app to be reused for the Flex app.

Anyway, the lightbulb went off and it dawned on me that my Mach II controllers should be talking to the service layer AND the controller functions in my Flex app could talk to the same service components without worrying about issues arising from framework specific code (as they would the way I have things coded now).

Now I have to go back and do a bit of refactoring, but even that will be easier because the application is now built with Mach II.  At least I learned something this week...