c# - What is the equivalent of static methods in ColdFusion? -
In C #, I have created steady ways to assist me in simple operation. For example:
Public Static Class StringHelper {public static string reverse (string input) {// reverse string returns reversed input; }} Then in a controller, I will call it using just:
StringHelper.Reverse (input); Now I am using Cold Fusion with model Gum, and I want to do the same thing. However, it seems that there is no concept of stable methods in coldfusion. If I make the CFC like this:
component stringheller {public string function reverse (string input) {// reverse string returns inverted input; }} Can I call this method by creating an example of StringHelper in the controller, such as: component Controller {Public reverse of zero function {var input = event.getValue ("input"); Var stringHelper = new string helper (); Var reversed string = string heller. Reverse; Event.setValue ("Reversed String", reversed); }} Or there is a place where I can put 'static' CFCs that framework will make an example behind the scenes, so I can use it as if it is static, like How do the Helpers folder work?
No, you are right, there is no concept of stable methods of cold melting. I think most people will solve this problem within the scope of application through the use of a single utility, which starts when the application starts. Therefore, you can have in the CFCC on your app:
& lt; Cfset application.StringHelper = createObject ("component", "path.to.StringHelper") /> Then whenever you are required to call it from anywhere:
& lt; Cfset reversedString = application.StringHelper.reverse (string) /> Yes, it is not clear as a steady way, maybe some day we could have something like that. But right now I think that it is as close as you would get.
Comments
Post a Comment