Web News


Making mobiles theft-proof with new technology
Mobile users who want to make their phones theft-proof can use a new technology developed by a US-based firm that is being offered in India by Chennai-based California Software Company Limited (Calsoft). The product....

Dubai Internet City finally gives nod for Smart City
The Rs.15 billion ($350 million) Smart City project at Kochi will soon become reality as its developer Dubai Internet City (DIC) has finally agreed to the revised...

Indian Unravels New Storage Format
An Indian by the name Sainul Abideen has reportedly discovered a method to represent data in the form of color combinations instead of the existing binary format that uses zeroes and ones. Abideen's discovery forms...

Indian teachers teach UK students online
In a major initiative, an Indian online private company has launched an on-line tuition service from India and is hoping to have 5,000 British students using it in a year's time. TutorVista, which claims to be the first Indian...


04.16.07


Coldfusion: Cfinvoke And CreateObject

By Raymond Camden

Gary sent in a question I've dealt with in the past, but I hear it brought up multiple times so I thought I'd share my response here.

First, Gary's question:

Simply asked, given the two examples below, how are these two methods different and what are the pros and cons of each. I'm leaning towards 'why is the creatobj method preferred?' This all goes to having a better understanding of OOP.


There are few different ways to answer this. First off - the result of both these code blocks is the exact same. They both call the init method on a CFC named blog, pass in a variable, and assign the result to a variable named application.blog. So if you consider the results - they are the same.

Technically of course they are different. One uses createObject and one uses cfinvoke.

Under the hood, I'd be willing to bet they compile down to pretty much the same code.

Try a Better Way Today.
Try WebEx MeetMeNow -
Click Here

So which is better?

The createObject method is typically what is used by most developers.

I'm not sure I'd call it a "standard" but I think you would see that in code more often than the cfinvoke version.

The cfinvoke method has the benefit of working on hosts, like GoDaddy, that block access to createObject.

What do I do? When creating an instance of an object using the init method, I'll always use createObject.

When calling a method on a CFC, I'll use simple script format (foo = mycfc.goo()) unless my arguments have complete logic in them.

If they do - I'll use cfinvoke since you can conditionally include arguments. Here is an example:



Comments

About the Author: Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.

About DevWebPro India
DevWebPro India is for professional developers ... those who build and manage applications and sophisticated websites. DevWebPro India delivers via news and expert advice New Strategies In Development.

DevWebPro India is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com NetworkNewz.com


-- DevWebPro India is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


New Strategies In Development DevWebPro India News Archives About Us Feedback DevWebPro India Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact