Coldfusion and the art of Object-Oriented Fu
I've picked up a small Coldfusion project this weekend and have been spending my evenings working on that. After spending so mcuh time away it's really great to come back to my first love: Coldfusion. I'm my time spent learning and dealing with other technologies (Java & EJB's, in particular) I've picked up a good bit of object oriented concepts but I still feel that OOP in Coldfusion still doesn't "click" and it's especially evident as I have come back to CF with this project. I get the concepts but I'm still at a loss when it comes to combining them all into something that adds value to my work. I could blindly start forcing everything into objects and messing around with DAO's and gateways but that seems counter productive to me. Especially when this project is so small and the tools that I developed years ago do the job just fine. While thinking about all this I was reminded of the excellent OOPhoto application put together by Ben Nadel. So I've been re-reading it in it's entirety and it's great to have someone else explore and articulate the same problems that have been filling my brain this past week.
My ideal solution would be to completely scrap my current application framework and move over to a ColdBox, ColdSpring, Transfer solution, but as we all know life is rarely ideal. And I really want to understand exacty what these frameworks are providing for me. Due to time constraints with this project I have come to a compromise (generally following Ben Nadel's first few steps, except lacking the actual entity objects) and I'm finding a few places to refactor and improve old code:
- Move all queries / database calls into separate service cfc's for each "object".
- Build a BaseService object to contain global functions.
- Build a nifty "ServiceFactory" to create the service objects and inject DB initialization info.
I realize that this could hardly even be considered a baby step in the direct of OOP but despite these limitations I'm quite happy with what I've refactored on this project. I no longer have to deal with updating SQL in many different places in my code. Each "thing" that I'm dealing with has it's own service to consume and I'm pushing more and more business logic into them. I really feel like I have to start somewhere and this is a quick way providing some immediate benefit.
My biggest questions right now are focusing around the "why's" of OOP. What sort of things can provide the most benefit to my CF apps without introducing bloat or complexity in the name of being pure OOP? Once again I'm finding the CF community an invaluable source of information. Thanks everyone! I'm definately going to be thinking about and developing my ideas on this subject in the coming weeks so any comments anyone may have are welcome!