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.