Go nuclear with Reactor for Coldfusion
I’m sure, like me you get extremely bored of doing add,edit,delete,add,edit,delete,add,edit,delete. Well i’ve always been looking for a quicker way to develop this sort of code, yes you can create templates where you just fill in all the variables, but more often than not you end up re-writing the whole thing anyway. Well finally, bingo! i’ve found out what i was trying to do is called an “Inline Dynamic Database Abstraction” API. The API is called the reactor framework. It basically allows you to create a table in your database and from that table you can perform all your database queries on-the-fly. Another great feature is that you can create relationships between tables via a simple XML file with this easy syntax:
<object name=”mRegion”>
<hasMany name=”sys_countries”>
<link name=”mRegionCountry” />
</hasMany>
</object>
<object name=”sys_countries”>
<hasMany name=”mRegion”>
<link name=”mRegionCountry” />
</hasMany>
</object>
<object name=”mRegionCountry”>
<hasOne name=”sys_countries”>
<relate from=”country_id” to=”country_id” />
</hasOne>
<hasOne name=”mRegion”>
<relate from=”regionID” to=”regionID” />
</hasOne>
</object>
This bit of code basically says a region has many countries and they link via a table called mRegionCountry.
It’s a lot more powerful than this but so far this as deep as i’ve gone. I’ve started using it in one of my applications and so far it’s saved me bags of time. I won’t go into details but after lots of googling i’ve found some very good documents the Introduction to Reactor for Coldfusion is great starter guide and is explained very simply with good examples. Also the .doc file that comes with the download is very good. Take a look at the examples too.
I’ll be posting more code in the future as I go along.
Aggregation using coldfusion components
Recently I’ve started using a more object-orientated way of programming but have found it is really starting to hurt my head. The main problems I have found seem to be with coldfusion itself. I am currently developing in CF7 and it doesn’t support multiple inheritance, it also doesnt have interfaces, as far as I understand, interfaces allow you to share methods across classes (components). I have found many articles written by Hal Helms on this subject which have helped but i’m still unsure that I am understanding the whole thing correctly.
Here is some code to show you what I have done so far…
contactObj=createObject("component","components.contact").init();
titleObj=createObject("component","components.contact.title").init(); titleObj.setTitleID( form.titleID )
contactObj.setTitle( titleObj );
contactObj.setFirstName( form.firstName );
contactObj.setLastName( form.lastName );
contactObj.setEmail( form.email );
contactObj.setUsername( form.username );
contactObj.setPassword( form.password );
contactObj.setContactID( form.contactID );
As you can see I have a setTitle() Method and this creates an object within contact of type “title”. The set title method looks like this:
<cffunction name="setTitle" access="public" returntype="void" output="false" hint="I set the title property">
<cfargument name="title" type="components.contact.title" required="yes" hint="title value" />
<cfset variables.title = arguments.title />
</cffunction>
The whole thing seems to work fine, but i’m still unsure i’m actually doing things correctly, sometimes you can go down a path and find out later that you should of been doing it a different way and it will cause you a headache further down the line.
I’d love to hear your thoughts on Aggregation using components and I’d also like to know if i’m doing it correctly.