Object-Oriented Blog Process - VIII

Inheritance code example.

To be honest I thought I would do this post much sooner. But life's been busy lately, and even though the code was already finished, I did not find the time to post and explain it.

Download here

As last time, unzip into a directory in your wwwroot and open index.cfm. One important thing to note: You need to be running the last updated version of CF (7.0.1) to be able to run the example code. Not because of the OO code, but because I choose to use a flash form to post the products into the "webshop". The reason is simply that this was the easiest way to make a form allowing me to insert two different product types. Sure it could have been done with some dhtml code, or just using multiple forms. But I choose to use flash forms (first time you open the page it takes a while to open). If you for some reason is not on the latest version on your develoment machine you could always rewrite the form code a bit your self.

I wont explain the form code here, as flash forms is not the subject of these posts (and there are many great resources on flash forms out there already).

The first thing to note is that where we do the createObject() method, we use a value from the form to deceide what kind of object we are creating. Then we are passing all the values from the form in as an argumentcollection.

The second thing to note is that when we loop over the products in the "webshop" there's now two different kinds of products with different attributes. So I'm using the getMetaData() method in each iteration of the loop to find out what kind of product I need to output.

The code in the cfc files are almost identical to the explanation I did for the inheritance post itself.

If there's any questions regarding this code, please feel free to contact me.

Comments