Object Orientation in ColdFusion is Probably Simpler Than You Might Think
When CFMX 6 came out and CFCs were first introduced, i bought a book by Hal Helms called Discovering CFCs. He introduces some basic OO principles in there, all of which are pretty easy to understand in theory. Then he starts off showing examples. I still remember how disconcerting it was to not be able to understand. And i couldn't put my finger on what it was that i didn't understand.
Looking back, i think there were a lot of little pieces i just didn't get.
Today, if i glance through the book, it all looks very simple and elementary. But i needed to do a lot of struggling to get to that point.
Seeing that i didn't understand something, and not knowing really what it was, i asked some questions and got some very good advice which books on OO patterns to read. So i bought a bunch of those and started reading about patterns.
That didn't help much. Keep in mind that i'm doing this on my own, in my spare time. So months have gone by and i'm not getting anywhere.
Finally i decided the only way i'm going to learn this is to try it out ... to build something. But i had a big problem in that at that time, there were no OO frameworks to piggy back on. I had to architect the whole thing myself. And i didn't know where to start, at all. I tried using UML, i had my nose in and out of my OO patterns books, trying to figure out if any of them fit.
That didn't go anywhere.
So i went back to some basic OO concepts and just wrote down all the nouns in my application on a piece of paper. And out of desperation more than anything else for having spent months going around in circles without getting anywhere, started trying to get something to work with one object for each noun.
Along the way, i found out that i didn't know a lot of little things. I didn't really understand how inheritance worked when i tried to actually use it with my CFCs. I didn't understand how composition worked either really. I was confronted time and again with situations where my Nouns as CFC's needed to work together somehow, but they were all stuck on their own islands, enclosed in their little encapsulated variable boundaries.
I remember the moment i began to think i understood what the word instantiation meant. Or the moment i began to get what it was to pass something - a variable or a structure or even another CFC, into a CFC. ("Oh, you can do that??!")
In a way, all i could do was hang in there like Helen Keller at the OO water fountain, and wait for some light bulb to click in my mind, not knowing which one it might be at any given time, or even if there is one.
It really doesn't have to be so difficult to learn to use a little OO in CF. Perhaps a few blog posts covering those little things that i didn't understand might help someone else? Look for them in the coming days ... or weeks.


I had a lot of "Oh, you can do that?!?!" moments myself. Learning OO is a process and can even be rather frustrating. The biggest tip I was given is to try out various things in a scratch pad area. If I had a question how something worked, I played around with it in the scratch pad area until I got it sorted.
I've certainly learned a lot from your blog posts and many posts on mailing lists. Thank you for your contribution to the community.
Dan Wilson
I also fund that my FuseBox experience really helped in getting my head around Mach II. After that it all kinda clicked.
Couple of points here:
1. Hal's book was written for CFMX 6.0 and is extremely out of date now (it talks about THIS scope everywhere because, back then, there was no working VARIABLES scope, no VAR scope and no thread safety). Just a caveat for anyone thinking about buying it.
2. You RSS feed is a bit broken - it doesn't encode spaces in URLs so quite a few RSS clients won't be able to jump to the actual articles.
Nice post. To follow up on Sean's comments:
(a) I couldn't get to this article from Bloglines so you do want to look into the feed!
(b) On the design side, check out Ward Cunninghams CRC cards. For more complex apps it can be a reat way to really start to "get" OO.
I learnt OO in about 1984, with smalltalk-80 and Adele Goldberg's book. I did a bit with THINK Object Pascal, then a loong gap until CFMX finally arrived (which at my company wasn't until about a year ago).
I found OO concepts very natural and very simple. Start with Logo, turtle graphics etc. It *is* simple. Learning the ins and outs of the Smalltalk image - not so simple, but always a clear path forward.
I started with CF in version 4.0. No function calls! In retrospect we were lucky to have skipped version 5, because I know I would have been coding function lookup tables to try to get some OO happening, and that would have all been wasted when - ta da! - CFMX came along.
Getting into CF OO was incredibly confusing. Classes aren't objects. No class methods. And what are all these beans/daos/gateways/services? So I started reading, and immediately ran into the enormous amount of baggage that CF carries, and which I think makes it a terrible environment for learning OO.
Firstly, J2EE casts a long shadow. Are you writing enterprise distributed transactional systems, or trying to get a handle on OO concepts? Both at once? You poor bastard.
Secondly, J2SE can be a pernicious influence as well. Why is Java statically typed? Basically to improve performance. So when looking to Java for inspiration, we're looking through the fog of a performance optimization that doesn't apply to CF anyway.
Thirdly, while I don't think anyone claims design patterns are going to help you learn OO, a lot of newbies seem to end up with the patterns books very early on. We need to make the message clearer - most of these patterns are complicated solutions for complicated problems.
Then there are CF's own performance issues. We pull our punches with OO modelling in CF, because the platform can't cope with instantiating lots of objects. Not a crippling problem, but not a good learning environment either.
Now, I don't realistically expect anyone is going to get Squeak or Logo or similar and spend time learning it as part of their CF skills update program, although I think that would be a good idea. But I do think a conscious effort needs to be made to peel away J2EE, Java, complex patterns, fear of object instantiation, worrying about the database layer, etc, etc.
That won't actually make OO in CF simpler, but it will get all the stuff that has nothing to do with OO out of our way so we can actually learn something.
Jaime
Hopefully a few blog posts here on the basics of using CFC's in an object oriented manner can help fill the gap.
And i can only wholeheartly agree with Jamie's statement about pattern books for people new to OO: "We need to make the message clearer - most of these patterns are complicated solutions for complicated problems." If you're new to OO and coming into it from a background in ColdFusion, i can only suggest that you focus on the basics first. Otherwise it's a little like taking a course in French law at a Paris university without knowing how to order a coffee and croissant from the corner cafe yet! I've tried it, i know!
And i just cleared out the alias i tried to set for this post. (Aliases shouldn't have spaces in them apparently.) Hopefully that clears up the RSS problem!