user2702375
user2702375

Reputation: 89

How to create classes and objects in ColdFusion, without using Java?

I am converting the PHP plugin to ColdFusion. In PHP, there are used OO concepts so classes and objects are used.

How I can convert those classes to ColdFusion class and create objects for those classes.

Also I have created Java class and using <cfobject> tag, I have created object, but I need ColdFusion classes and created objects.

Please let me know if you have any ideas.

Upvotes: 0

Views: 2908

Answers (2)

Adam Cameron
Adam Cameron

Reputation: 29870

Realistically you should be able to solve this by reading the docs a bit more thoroughly than you already have. However this question is fairly easily answered. Firstly let me disabuse you of something though:

there is no option to create classes in coldfusion without using the java,com and corba

This is just you not reading properly. Even on the page you link to (cfobject, which is pointing to an obsolete version of ColdFusion btw), the third link it provides "component object" discusses instantiating native CFML "classes" ("components" in CFML parlance, for some reason). It's perhaps not clear from top-level browsing that a "component" is a "class", but if you're learning something, you should be doing more than top-level browsing.

You are approaching your learning from a very odd angle: reading up on how to instantiate an object is not the direction you ought to be taking if you want to find out how to define the class the object will be an instance of. It kinda suggests a gap in your knowledge of OO (which could make this work a challenge for you).

Anyway, of course CFML allows for the definition of classes and the usage thereof, natively in the language. And has been able to do so since v6.0 (although this was not really production-ready until 6.1, due to some poor implementation decisions), over a decade ago.

The answer to your broader question, can be found by reading the docs starting with "Building and Using ColdFusion Components". But the basic form is:

// Foo.cfc
component {
    public Foo function init(/* args here */){
        // code here
    }
    // etc
}

And that sort of thing.

Upvotes: 1

Sanjeev
Sanjeev

Reputation: 1866

ColdFusion does have classes and objects and follows limited OOPS principles. You can do inheritance, interfaces. Polymorphic functions is still not allowed.

Classes in ColdFusion are called as Components. CFC -> ColdFusion component. Depending on the ColdFusion version, you can write them in script mode or in tag mode.

You can refer to the documentation for CF8 about creating component and their objects.

The createObject() method you have mentioned is one way of creating different type of objects. The other ways are to use <cfinvoke> or <cfobject>

Hope this helps. Just read the docs in detail and they will help you every time.

Upvotes: 6

Related Questions