 |
|
 | |  |
|
cpnet
|
 |
Posted: Mon Jun 27, 2005 9:26 pm |
|
 |
 |
 |
 |
After reading your post about CFC's, I found a bunch of articles on them at macromedia.com. Despite the claim in a number of the articles that CFC code is more simple than traditional OO code, I find it much more complicated. (I'm not just comparing CFC stuff to MS OO languages, but Java too). I think the XML/HTML-ish syntax of CF really limits it to presentation layer tasks. It just doesn't seem very practical for dealing with programming of other tiers. I think this is understandable though, because CF has always been about the presentation tier. I think if CF wants to compete in programming the other tiers, they need to improve the syntax of their language.
I'm also curious to see how you would handle the experiment using a CF/Java mix. Actually, I'd like to see a simple end-end solution implemented both in CF (and whatever other technologies, maybe Java) vs. the same solution completed in .NET. A frequent .NET claim is that .NET requires less code to do the same thing as Java and some seem to imply that CF is a better UI tool than ASP.NET. I'd like to see what's involved in each solution.
|
|
|
 |
 | |  |
|
Josh
Forum Regular
| Joined: 01 Apr 2004 |
| Posts: 1029 |
| Location: Felton, Delaware |
|
 |
Posted: Mon Jun 27, 2005 9:43 pm |
|
 |
 |
 |
 |
A CFC is not a class... not by any means. At best, a CFC is like a custom user control for ASP.NET.
Okay... I tried something else... instead of using CFC, I researched using CFScript... that's MUCH more straight forward than any CF i've seen to date. In fact, it goes into even more depth talking about UDF's and EJB's. It seems that when you define a CFScript section that you're programming in java. So that's how CF and Java talk back and forth in a simple manner. That's fascinating!
Check this out...
http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001570.htm
and
http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00001570.htm
Good stuff there!!!
Apparently, creating a class for use with CFMX is a trivial task as long as you understand Java (which is pretty easy for any C#er) then you've got your work cut out for you. Now we're getting down to the nitty gritty... but it seems you can't do that with CFTags... which will hold ALOT of people back who are either unaware or unwilling to get into Java.
In fact, I can see now how one could seperate the application and presentation layer in CF if they really wanted to... but 99% of people out there won't.
|
|
|
 |
 | |  |
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 12:39 am |
|
 |
 |
 |
 |
ok there were a lot of comments here I will try to address them
1. scott the code i showed you is what you want to see, that cfc isn't just just populating a recordset it.s making that whole structure, thats how a cfc works it's just awhole lot less code than the .net way. The code you provided in .net doesn't do anything more than the cfc method.
here look, here is a cfc for a simple guestbook that retrieves the messages and adds new ones
<cfcomponent hint="Insert and Get Users Comments">
<!--- Define a function to add comments --->
<cffunction name="InsertNewComment" access="remote" returntype="string" hint="Add new comment">
<!--- Define required parameters --->
<cfargument name="FirstName" type="string" required="yes">
<cfargument name="LastName" type="string" required="yes">
<cfargument name="Email" type="string" required="yes">
<cfargument name="Message" type="string" required="yes">
<!--- Get Current Date --->
<cfset Date="#DateFormat(Now(), 'yyyy/mm/dd')#">
<!--- Insert new record into the DataBase --->
<cfquery datasource="GuestBook">
INSERT INTO tblContent
VALUES('#FirstName#',
'#LastName#',
'#Email#',
'#Date#',
'#Message#')
</cfquery>
<!--- Specify result as string --->
<cfset result="Your comment has been added successfully.">
<!--- Return result of the function --->
<cfreturn result>
</cffunction>
<!--- Obtain Comments --->
<cffunction name="GetComments" access="remote" returntype="query" hint="Get a list of comments">
<!--- Get all fields from DataBase --->
<cfquery datasource="GuestBook" name="Info">
SELECT *
FROM tblContent
ORDER BY "Date" DESC
</cfquery>
<!--- Return result of the function --->
<cfreturn Info>
</cffunction>
</cfcomponent> |
and say you want to call it as a web service
http://www.jamwerx.com/GuestBook/GuestBook.cfc?wsdl
thats just a straight easy cfc that can be used as a web service, to import into flash as a query, web service, via remoting, soap, whatever all from that code.
| Can something like this class be replicated in ColdFusion? If so can you show me the code to do it? |
i already did!!!!
How would I, in CF, create a player object that I can store in memory and manipulate etc etc etc? |
there are several ways, the easiest is the one i already showed you
<!--- create CFC objects --->
<cfobject name="playerInfo" component="cfc.playerStats">
run that in th Apllication.cfm file and it creates a java object ready whenever you need it.
#BarryBonds.Homeruns#
We can now take this player and make a 9 item array of players and we now have a team.
Note that I calculated the batting average, slugging percentage and steal attmepts within the object and that the positions property is an ArrayList. If you're not familiar with what an array list is it's just a dynamically sized array.
|
I know what an array list is and yup you can do that with the return value from the cfc, you can do anything you want with it, throw regex's is, send to list, appendlist, appendstructures, whatever you really want.
welcome to the power of coldfusion scott!
| How would I, in CF, create a player object that I can store in memory and manipulate etc etc etc? |
we have already covered that, once you create the object you can do whatever you want with it, say on one page you want batters and another you want pitchers, you can just use the same ouput and filter it through the calling page.
| Or is that something that you would have to do in Java? |
nope, you make it in cfm and it compiles to java
| anybody can find these deep dark secrets in CF it's him. |
amen! ;)
I can't give u all the secrets!!
Again it all goes back to the user as to how OOP it will become or how sloppy and crappy it will become. Say if Scott picked up some cfm he could do some amazing things with it and then run it on a bluedragon server and be able to leverage not only java with cfm but .net as well and thats a beauty of it! Say you need RAD then use cfm and say you have a decent code for manipulating images in .net, you can natively run the cfm code into the bg server with your .net code then say you want to deploy it all as a single WAR file on a UNIX j2ee server, just zip it up up deploy it.
You gotta admit that's pretty cool!
| Should we pull in overloaded methods, too? Wink |
well you can easily control those in your cfc as well, 1 cfc can do a million different things if you want to make it that big, the easiest way is to base the cfc method on a arugument. trivial....
| But if this is Java stuff not CF then I understand...if CF can't do it - it can't do it. |
I haven't really seen anything yet that cfm can't do Scott.
| That's prolly why they built CFMX on top of the Java J2EE stuff so that if you NEED this kind of power and flexability, all you have to do is learn Java AND ColdFusion then get them both working together. |
No it was built upon the j2ee platform for a lot of reasons but the main was power, speed and leverage that it enables, not to mention scalabily, deployment options, etc.
| just the CF stuff since most CFers don't use Java. |
it's pretty rare that you need that extra power and you would be suprised how many actually do know a lot of java, actually a lot of the newer cfmers are coming from java & jsp as they are finding out that most everything they they were doing (slowly) is now being down 3x-4x faster in cfm with the same results.
| but my thinking is always rejected by lofty Sad |
it's the way you say it, probably the same way I say things about winblows that are taken wrong. But in this case you came in and tried to blast cfm from what you knew about cfm from last century and that kinda crappy comparisons won't fly.
| That's 5 more revisions of CF than I have ever used... |
Scott, cfm 5 was the last version of coldfusion that was a tag runner and the last to be made by the founding company Allaire. CFMX was completely rebuilt from the ground up and instead of being a tag runner it was made on j2ee that compiles java byte code, the same as jsp, they just get there in different ways.
I (finally) found a tutorial on using some simple OOP stuff in CFMX...I really hadda look hard. I was hoping just to find a simple "Here is how you make a class in CFMX" tutorial - but they don't exist. I think it's because they are called ColdFusionComponents instead of classes... |
right, coldfusion componrnts or cfc's or you can make them in java with jsp tags or in cfm inside UDF's.
| really limits it to presentation layer tasks. |
no, the person doing it limits that, it's pretty easy to seperate content from presentation, especially with cfc's.
| I think this is understandable though, because CF has always been about the presentation tier. |
that's not correct, cfm has always been about RAD.
I'm also curious to see how you would handle the experiment using a CF/Java mix. Actually, I'd like to see a simple end-end solution implemented both in CF (and whatever other technologies, maybe Java) vs. the same solution completed in .NET |
Pet market is what you are looking for, read till your heart is content
http://www.macromedia.com/cfusion/search/index.cfm?loc=en_us&term=pet+market&area=&action=Search
j2ee vs .net
http://www.macromedia.com/devnet/mx/blueprint/articles/performance.html
granted thats java not cfm vs .net, the cfm has less lines of code then the .net version
| A CFC is not a class... not by any means. At best, a CFC is like a custom user control for ASP.NET. |
i think u must smoke some good crack;)
Okay... I tried something else... instead of using CFC, I researched using CFScript... that's MUCH more straight forward than any CF i've seen to date. In fact, it goes into even more depth talking about UDF's and EJB's. It seems that when you define a CFScript section that you're programming in java. So that's how CF and Java talk back and forth in a simple manner. That's fascinating!
|
cfscript has been around for a long time josh and no thats not how they talk to each other, well they can but thats the old way.
| Apparently, creating a class for use with CFMX is a trivial task as long as you understand Java |
Apparently you have no idea again, you can jusy use cfobject and make a **** java object, you guys are really trying to hard to try and make this look hard cause it's not.
| which will hold ALOT of people back who are either unaware or unwilling to get into Java. |
I don't know java and it doesnt hold me back, the ppl that are held back because of that are retards.
| In fact, I can see now how one could seperate the application and presentation layer in CF if they really wanted to... but 99% of people out there won't. |
It's pretty easy to do and thats also like saying 99% of the ppl who use .net or php don't actually program in OOP, cause they don't.
anything else?
if you want frameworks then look at
model-glue
fusebox
mach ii
onTap
plum
sky skraper
there are quite a few of them.
|
|
|
 |
 | |  |
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 12:43 am |
|
 |
 |
 |
 |
Components bring to ColdFusion MX developers much of the power and practices of object-oriented programming. The component implementation in ColdFusion MX introduces us to many of the principles of OOP, including encapsulation and inheritance. One aspect of these features is the ability to create new components that inherit or extend the functionality of other components.
In order to effectively extend functionality, developers often require the ability to override existing component functions as well as still call the original functions to incorporate their programming logic. Since ColdFusion MX doesn't currently provide this ability, we'll explore a technique to work around this limitation that enables us to call a parent component's overridden method.
Component-Based Development
With component-based development, related code can easily be grouped together in a consolidated entity, giving us the ability to encapsulate data and functionality. This consolidation can be further expanded with the ability to inherit functionality from a parent component, also called extension. When one component extends another, it can both reuse the functionality of the original component and add its own functionality.
Often, the new functionality added to a component will replace its original functionality. This is an advantage to developers who utilize the component in their code since the parent and child components will each have a similar call interface, or function names. By maintaining a consistent interface, developers can write code that can use either the parent or child component interchangeably without modifying the calling code.
For an example of this, see Listing 1, which sets up two components, GreetingBase.cfc and GreetingChild.cfc. GreetingChild extends the functionality of GreetingBase, and both provide a single function, sayGreeting, which returns a greeting to the caller. The caller can use either component and call the same function to retrieve the result appropriate for the component being used, a feature known in OOP as polymorphism.
Listing 1:
Parent and Child components each with their own sayGreeting function
<!--- GreetingParent.cfc --->
<cfcomponent displayName="Greeting Parent Component">
<cffunction
name="sayGreeting"
returnType="string">
<cfset var greeting="Hello">
<cfreturn greeting>
</cffunction>
</cfcomponent>
<!--- GreetingChild.cfc --->
<cfcomponent
displayName="Greeting Child Component"
extends="GreetingParent">
<cffunction
name="sayGreeting"
returnType="string">
<cfset var greeting="Hi there">
<cfreturn greeting>
</cffunction>
</cfcomponent>
Calling Overridden Parent Component Functions
We run into a limitation when we try to utilize the parent component functionality for a function that we've overridden, in this case sayGreeting. We want to add a function sayAllGreetings, which returns the results of both the parent and the child components' sayGreeting functions. While you can create an instance of the parent component and call the new instance's sayGreeting method, this would not return accurate results in cases where the call depends on data in the component instance. Unfortunately, there is no mechanism in ColdFusion MX to call an overridden parent method and have it run in the context of the calling component instance.
Many other OOP languages, such as Java and even ActionScript, allow calling a parent class's methods through the keyword Super. While ColdFusion MX does not provide this ability, there is an often-overlooked feature that we can use to achieve the desired effect.
ColdFusion stores function references and variables equally. A function can be called by referring to the function name followed by parentheses, as you are accustomed. Additionally, the function reference can also be utilized by simply referring to the function name. The most common utilization of this feature is to copy a function to another scope, and here we'll use this ability to make a parent component's functions available to its children.
Any code that exists within the cfcomponent tags and outside of any cffunction tags is executed when the component is instantiated. This code is most often used to set up or initialize the component and is called the Constructor in OOP terms.
<cfcomponent>
<!--- constructor code goes here --->
<cffunction name="...">
</cffunction>
</cfcomponent>
In Listing 2 we added some code to our original components. GreetingBase.cfc now has two lines of code in the constructor.
<cfset super = structNew()>
<cfset super.sayGreeting = sayGreeting>
Listing 2:
Parent and Child classes each with their own sayGreeting functions
<!--- GreetingParent.cfc --->
<cfcomponent displayName="Greeting Parent Component">
<!--- set up a structure to hold super class methods --->
<cfset super = structNew()>
<cfset super.sayGreeting = sayGreeting>
<cffunction
name="sayGreeting"
returnType="string">
<cfset var greeting="Hello">
<cfreturn greeting>
</cffunction>
</cfcomponent>
<!--- GreetingChild.cfc --->
<cfcomponent
displayName="Greeting Child Component"
extends="GreetingParent">
<cffunction
name="sayGreeting"
returnType="string">
<cfset var greeting="Hi there">
<cfreturn greeting>
</cffunction>
<cffunction
name="sayAllGreetings"
returnType="string">
<cfset var greetings="Parent says '" &
super.sayGreeting() &
"', Child says '" &
sayGreeting() & "'">
<cfreturn greetings>
</cffunction>
</cfcomponent>
What we've done here is set up a structure called "super", which we'll use as a holder for our parent component methods. After creating the structure we use cfset to copy a reference to the function to our structure. It's important to note here that when this code is run, the component will exist only as the parent component, so any functionality that is overridden in the child component has not yet been incorporated.
With this structure created and our parent functions safely stored, we can utilize them in the child, GreetingChild.cfc, as follows:
<cfset var greetings="Parent says '" &
super.sayGreeting() &
"', Child says '" &
sayGreeting() & "'">
In this code we put together a string in which we call our parent component's sayGreeting function, through our super structure, and also call the current sayGreeting function as we normally would.
Super Structure Limitations
Through a little creative utilization of obscure features, we've been able to implement a very important feature common to OOP. However, our implementation is not comprehensive and does have limitations.
This technique can only be used to implement one level of parent-component calls. Since each component in the inheritance chain does not have its own data location where we can store the parent component's methods, we can only store the methods from a single parent component.
Additionally, we must recognize that this is a workaround to provide for functionality missing from ColdFusion MX. Since this feature is standard for OOP and commonly requested from developers, Macromedia will probably implement this functionality natively in a future version of ColdFusion.
When adding support for parent-component calls, Macromedia is likely to use the keyword "super" in their own implementation since this is used in both Java and ActionScript. With this change, our code will stop working since "super" will become a keyword. While this may seem like a problem, it is actually an advantage.
Since we no longer need our workaround once parent component calls are implemented in ColdFusion, we want to ensure that we can easily remove this workaround when it becomes obsolete. To accomplish this, wrap all of the super workaround code, the parent-component constructor, inside consistent comments as shown in Listing 3.
Listing 3:
Parent component with comments added
to facilitate removing the super structure
<!--- GreetingBase.cfc --->
<cfcomponent displayName="Greeting Parent Component">
<!--- start super hack --->
<cfset super = structNew()>
<cfset super.sayGreeting = sayGreeting>
<!--- end super hack --->
<cffunction
name="sayGreeting"
returnType="string">
<cfset var greeting="Hello">
<cfreturn greeting>
</cffunction>
</cfcomponent>
Download the Code ...
Go to www.coldfusionjournal.com
With these comments, we can utilize the Regular Expression replace in either ColdFusion Studio or Dreamweaver to remove all of the super structures from our code. As long as the keyword super is used for this functionality natively, the rest of our code will continue to work.
Conclusion
Component-based development brings to ColdFusion MX many of the features of OOP. By using a structure and function references, we were able to bring a common feature of OOP to ColdFusion, albeit with limitations. In recognizing these limitations, we can write our code in a forward-thinking manner and facilitate future changes to the code when they come in conflict with possible new functionality.
Samuel Neff is a senior software engineer with B-Line Express in the Washington, DC, area. He is Advanced ColdFusion 5.0 Certified and a Team Macromedia Volunteer for ColdFusion.
sam@blinex.com
|
|
|
|
 |
 | |  |
|
Josh
Forum Regular
| Joined: 01 Apr 2004 |
| Posts: 1029 |
| Location: Felton, Delaware |
|
 |
Posted: Tue Jun 28, 2005 1:24 am |
|
 |
 |
 |
 |
Interesting to say the least... I guess a CFC really is a good modular way to implement class structures... it's just that taggy crap  It throws me off... the property=value stuff is just different than the way all the other big players present their structures and syntax. But apparently everything you need to do you can do with tags... Doesn't mean I have to like it though (still ew) LOL
Great stuff, Dave. I think that's what alot of us were looking for. It's quite amazing to see where CF has gone since 5. Yeah, I inevitabley follow little bits and pieces but so much more of my time goes into .NET. That's be like expecting you to be a .NET vet  And right now im drowning in work so there's even less that Im up on than usual. Dont get me wrong... Like I said, I dont follow CF very much anyway.
CFScript is so much easier on the eyes... so much simpler to understand and read. Guess If I was willing to buy new glasses I'd have taken the time to study the tag syntax alittle more, but it hurts my head.
BTW... I didn't use CFScript in my CF phase... guess it was too hard back then  LOL (joke... joke... n00b developer  )
|
|
|
 |
 | |  |
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 1:32 am |
|
 |
 |
 |
 |
I hear ya josh
and you know I get you going by ripping on you because it works
I understand that some people don't like the syntax and that goes both ways, I am used to it and I like it, lets me fly through my work and gives me many options as too how I want to make and deploy my sites.
The thing with cfm right now is that most people still think of it as a simple tag runner and it's grown way past that since then. The same goes with PHP, ppl say it's come so far in such a short time but did you know PHP is as old as coldfusion (10 yrs)!! I think both have taken great strides in the last few years though.
I think for whitesite who will be using a lot of flash that cfm is a good way to go as it's native for flash and flex to seamlessly pass data back and forth and if you haven't seen how it works with flex, oh man that is some serious 
|
|
|
 |
 | |  |
|
Josh
Forum Regular
| Joined: 01 Apr 2004 |
| Posts: 1029 |
| Location: Felton, Delaware |
|
 |
Posted: Tue Jun 28, 2005 1:42 am |
|
 |
 |
 |
 |
If white's talking about interfacing with large amounts of flash, I have to agree with you. But for anything else, we all know CFM is childsplay compared to ASP.NET.
j/k LOL :
Yeah I keep looking at PHP but there are certain things that I still don't like about it either. And with .NET being able to interface with as many if not more DB systems as PHP and being able do accomplish all the same things, some with less code or more control (depending on what's needed), I just don't have any incentive to learn it.
And with as much work as I'm doing right now, I don't need to be picking up ANYTHING else. Between work and teaching my schedules chock full.
|
|
|
 |
 | |  |
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 1:52 am |
|
 |
 |
 |
 |
i hear ya, I accidently spammed 10,000 ppl, was supposed to only be 103 and I got over 10 orders for sites just last week and still have 47 more quotes to get out. ANd this includes 2 corperations already as well...
This is when I smile and say TG 4 cfm
You know what I like about cfm? it helps u spell check lol
yeah the php deal is for the birds
|
|
|
|
Josh
Forum Regular
| Joined: 01 Apr 2004 |
| Posts: 1029 |
| Location: Felton, Delaware |
|
 |
Posted: Tue Jun 28, 2005 2:02 am |
|
 |
 |
 |
 |
oops.
|
|
|
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 2:06 am |
|
 |
 |
 |
 |
yeah but it brought lots of biz so i cant complain
|
|
|
 |
 | |  |
 |
 | |  |
 |
 | |  |
|
Josh
Forum Regular
| Joined: 01 Apr 2004 |
| Posts: 1029 |
| Location: Felton, Delaware |
|
 |
Posted: Tue Jun 28, 2005 4:40 am |
|
 |
 |
 |
 |
So im looking around and reading, because now im really interested... it seems that CF doens't actually have constructors... And code found in the CFC but outside of a method is immediately executed... which is not a constructor. You cannot pass parameters to anything because that would require the constructor to be a method.
A constructor is a function provided by a class in an object-oriented language to instantiate an object, to name it and initialize it. The constructor function has the same name as the class. A class may also have a destructor function to destroy objects of that class.
Am I correct, Dave? This is a question... not an attack. Trying to clear up some things with this now. Because if that's the case, then there really isn't true support for classes. It's kinda along the line of PHP if that's the case.
I know you can do it via java, but im talking about the taggy stuff right now...
|
|
|
 |
 | |  |
|
loftboy
Forum Regular
|
 |
Posted: Tue Jun 28, 2005 4:58 am |
|
 |
 |
 |
 |
umm, im not really sure but you can pass things along just fine, like variables, params ect between cfc's
I have heard some say yes and some say no, the person I need to ask from MM is on a plane right now heading your way for cfunited.
creating a java object isn't tough though, I'm not sure why you are so opposed to that?
the 1st links from a google search
http://www.cfczone.org/faq.cfm
http://www.phptr.com/articles/article.asp?p=31755&seqNum=5&rl=1
http://livedocs.macromedia.com/wtg/public/coding_standards/goodpractice.html
http://www.oreillynet.com/pub/a/javascript/2003/09/24/coldfusion_tips.html
there is true support for classes, you just need to realize that cfm & java are together now and if you don't yet know java you can't discount that from cfm because thats a shortcoming of the developer not the language. 
|
|
|
 |
 | |  |
|
bobum
Elvis Fanatic

| Joined: 16 Nov 2004 |
| Posts: 746 |
| Location: Montgomery, AL |
|
 |
Posted: Tue Jun 28, 2005 1:08 pm |
|
 |
 |
 |
 |
| loftboy wrote: | ok there were a lot of comments here I will try to address them
1. scott the code i showed you is what you want to see, that cfc isn't just just populating a recordset it.s making that whole structure, thats how a cfc works it's just awhole lot less code than the .net way. The code you provided in .net doesn't do anything more than the cfc method. |
I don't see it. All I see in that snippet of CFC you sent me is a hit on a database and a return of recordset. I can do that in .NET as well as you in nearly as many lines of code. But that recordset is not a datatype that I created. I don't know how else to explain it. The recordset doesn't have public & private members, it doesnt' have methods etc. It's just a flat file recordset returned from the database. I can do that in Classic ASP, but I can't replicate that class because classic ASP isn't OOP.
I want to see the ColdFusion datastructure representation of that player. Not a select statement.
This is the closest thing I've seen to actaully creating a class in CF and inheriting that class to other classes.
http://www.macromedia.com/devnet/mx/coldfusion/articles/supsub.html
Note that in this article there is no call to a database...just like in my player example...
|
|
|
 |
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
All times are GMT
Page 3 of 6
|
|
|
|
|