The Joy of CFCs
A few years ago I started a project that I knew would likely be the largest I had yet attempted. The project would also be my first on ColdFusion MX, so CFCs seemed like a good tool to keep my code organized.
As it was my first project with CFCs, I had no experience with how best to utilize them. I read about objects and design patterns. Reading, of course, doesn't substitute for experience. Still, I have been happy with the result overall.
This week, as I was changing some functionality per some new requirements, I discovered that I had written one piece of functionality three different times in three different CFCs (talk about violating DRY!).
I changed the constructor (well, the init method) of two of the CFCs to pass in a third. I was then able to call the functionality from one place. This change in code in the CFCs didn't change the methods or arguments in the CFC except the init method. The result is that I didn't have change any of the code throughout the application that relied on this functionality.
Basicaly, I kept the API the same and so I was able to change the guts of how my logic worked without needed to change any of the code that used that logic (of which I had a lot). I could do this because I had used CFCs in a well-encapsulated way and had maintainted the API of the CFCs.
The point (if there is one) is that if you are thinking about using CFCs but you are worried that you don't know enough to take full advantage, I would encourage you to go ahead and give it a try. Even if you don't use them correctly, you will probably be ahead by using them. I have been.
Keep up the good work.
Thanks. I was. I haven't subscribed again after the mail server issues, but I plan to soon. I have really enjoyed that list and I would recommend it to others as well.
Gary,
I agree completely. I have been asked about the advantages of CFCs many times and I have often had a hard time enumerating their benefits clearly. So this seemed like a perfect example of their benefits.