Yo, Adrian! Instead of having multiple cfc's, can one have just 1 cfc?

Posted on March 20, 2008

A reader of my OOCF Primer asks: “Instead of having multiple cfc’s can one have just 1 cfc?” The answer is: it depends.

Q: Can you have 1 CFC that is both a Gateway and a DAO?

A: Yes and that would make Sean Corfield very happy.

Instead of having a ContactDAO.cfc for CRUD methods and a ContactGateway.cfc for record set methods, you can have just ContactDAO.cfc that contains them all. There are pros and cons to this and I’ll go into more detail in a later post. For the sake of learning OOP with ColdFusion, I (and others) prefer to use both so that we can separate code and focus each CFC on certain tasks.

Q: Can you have 1 CFC that is both a DAO and a Bean?

A: Yes, but I don’t recommend it.

I’m going to cover that in detail as well, but the premise has to do with caching objects in server, application or session memory and the problems you could have doing that with a CFC that has both Bean and DAO methods.

Q: Why so many CFCs?

Right now I know it seems daunting to have so many CFCs. For those learning OOP with ColdFusion we’re going step by step through what each type of object does and why. Eventually we’ll get to where we can use less objects for some tasks and more objects for others.

If you think 3 (Bean, DAO and Gateway) is a lot of CFCs now, just wait a few weeks. :)

About the Author
Adrian J. Moreno

Adrian is a CTO and solution architect specializing in software modernization. More information