At times, I like to push the limits of the languages I work in, just to see what I can learn. A while back,
I got the idea of using structs as objects in Coldfusion, since instantiating objects is so slow. Of course,
this would only be useful if you had tons of objects, and if it was substantially quicker than creating
real objects. Anyway, I decided to see what I could come up with.

Unfortunately, I don't think this would be any more efficient (and possibly less),
because I need to do three file operations. But, I thought I'd share what I came up with regardless.

Basically, what happens is that you tell pseudo_object.cfc what object you want to create, and it creates
a fake object that behaves like a real one. It reads the CFC
you tell it you want an object of. It creates a struct, finds the name of the variable you stored it in
(multiple references won't matter, to my knowledge), rewrites the methods to use the scope+name of
that variable, plus an extra this or variables scope to make up for
variables named the same in different scopes within the CFC. Then, it attaches those methods to
the struct and you now have a struct which behaves like
an object. It won't work if you have any code outside of methods, however. Also, another problem may
arise if you have something like this.variables.

Since I'm not entirely sure that made any sense, I'll share the code now:

Now, it was fun to play around with this stuff, but I realize it's probably useless (I mean, I didn't do
any benchmark testing to see if it was faster than object creation, since I had to read and
write to the file system). Further, I'm not at all happy with the design. My main concern is that the
semantics are exposed: a user of this code needs to know they have to call the methods in the order shown
in test_pseudo_object.cfm to have it work. That could be fixed however, if I required that the name of one
of the variables (and its scope) be passed into the CFC via the init() method. Then,
it would return the struct, all in one go. In fact, if I were to ever start using this, I would reimplement
it in that fashion, and it wouldn't be very hard.

Anyway, what do you think of this useless ...

Hey! Why don't you make your life easier and subscribe to the full post
or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate
wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!

this was done back in the CF4.0 days. I was really cool and useful at the time before cfcomponent came along. Sometimes I wish Macromedia would of had Ralph on the team when they decided to implement objects in CF.

Cool! I started using CF in version 4.5, and cfobjects sounds familiar to me, but I don't recall what it was! I read a little bit on that site. I notice a method to invoke methods... wonder how that worked? I guess I'll have to check it out more in depth later.

Of course, I don't recall cffunction being around until CF5 (not sure if it was out before then, but I don't recall knowing about it until that time), and I probably never used it until CF6. My memory can be hazy at times, especially that far back, so take that into consideration before relying on anything I say from way back when. =)

Also, it appears I'm slow to adopt new technology... or else I used to be. Now, I try to be at least a little more up to date... =)

CFObject although cool, never really caught on. For one thing, you had to have mapping placed on the server and at that time hosting companies were reluctant to do so. Also before cfcomponent many people didn't see a need for objects in web development.

Ralph was a really ingenious guys and I remember seeing his presentation on CFObject a couple of times at my CFUG. I tried to use it after that, but I guess my brain was cluttered with procedural programming stuff, because it didn't really start to make sense until I started using cfcomponents.

Actually, CFObject was kind of inspiring when it first came out. I took it apart, then built a new one based on the file=method inheritance and polymorphic principles, did away with the registration and garbage collection, and added CRUD/business object functionality.

Went through about three versions refining it and adding features, used as the base for four or five production sites, and was about to release it to the community when MX6 and components appeared on the scene.

Your email address is not displayed.
It is used only to respond to you if needed, and
send comments if you subscribe to this comment thread.
It is stored in a cookie if you choose to "Remember my details".