ColdFusion and OOP

questions about CF and OOP

Page 1 of 1

4 Replies - 2137 Views - Last Post: 29 August 2007 - 11:05 AM Rate Topic: -----

#1 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

ColdFusion and OOP

Posted 14 August 2007 - 01:52 PM

ok so I have this book "Discovering CFCs - ColdFusion MX Components" it was written in 2002 I am new to ColdFusion and while I am following the book OK, there are things in it that the beginning of the book that he says will return an error, he even put a screen shot of the error....well I didn't get an error. And now I am learning about supertypes in ColfFusion and you have to write the constructs and it is this big huge redundant process, and he keeps saying 'in real OO languages you can just do it like this: _____ but in ColdFusion you have to write your own constructs" and its a big long non-understandable process...and my code is returning differently than his, and I am just wondering, has ColdFusion improved it's use of the OO concept since 2002? and where would I find a better updated more accurate book so that I could learn it?

Please no advice on what I need to learn instead or should start out with, I am very bull headed and this is what I want to learn, no one will change my mind. Sorry and thanks

Kacie

Is This A Good Question/Topic? 0
  • +

Replies To: ColdFusion and OOP

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1866
  • View blog
  • Posts: 20,278
  • Joined: 17-March 01

Re: ColdFusion and OOP

Posted 14 August 2007 - 01:56 PM

First, you're on the right track OO in ColdFusion actually makes the language fun and not so mind numbing.

Second, yes, OO in CF is not like OO in other languages... it's pseudo OO.

Third, Yes, things have changed a lot since CF 6 and CF 7.

And finally, I would recommend reading up on Hal Helms, he's does a GREAT job of explaining OO in CF:

http://www.halhelms.com


Books, not sure, I know there are some newer books that focus on OO and CF7 and now maybe even CF8.
Was This Post Helpful? 0
  • +
  • -

#3 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: ColdFusion and OOP

Posted 14 August 2007 - 01:58 PM

View Postskyhawk133, on 14 Aug, 2007 - 01:56 PM, said:

First, you're on the right track OO in ColdFusion actually makes the language fun and not so mind numbing.

Second, yes, OO in CF is not like OO in other languages... it's pseudo OO.

Third, Yes, things have changed a lot since CF 6 and CF 7.

And finally, I would recommend reading up on Hal Helms, he's does a GREAT job of explaining OO in CF:

http://www.halhelms.com


Books, not sure, I know there are some newer books that focus on OO and CF7 and now maybe even CF8.

thank ya thank ya
Was This Post Helpful? 0
  • +
  • -

#4 supersssweety  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 22
  • View blog
  • Posts: 373
  • Joined: 16-March 07

Re: ColdFusion and OOP

Posted 15 August 2007 - 11:05 AM

View Postskyhawk133, on 14 Aug, 2007 - 01:56 PM, said:

First, you're on the right track OO in ColdFusion actually makes the language fun and not so mind numbing.

Second, yes, OO in CF is not like OO in other languages... it's pseudo OO.

Third, Yes, things have changed a lot since CF 6 and CF 7.

And finally, I would recommend reading up on Hal Helms, he's does a GREAT job of explaining OO in CF:

http://www.halhelms.com


Books, not sure, I know there are some newer books that focus on OO and CF7 and now maybe even CF8.


kk Hal wrote the book I am learning from...


The point is to pass arguments using two different classes: 5Employee and 5Person (I put the 5 in front to find the files easily in my directory) here is the code

5Person.cfc:
<cfcomponent>
	<cffunction name="new">
	  <cfargument name="firstName" required="no" type="string" default="null">
	  <cfargument name="lastName" required="no" type="string" default="null">
	  <cfargument name="yearBorn" required="no" type="string" default="null">
	  <cfargument name="subtype" required="no">
	  
	  <cfset this.firstName = arguments.firstName>
	  <cfset this.lastName = arguments.lastName>
	  <cfset this.yearBorn = arguments.yearBorn>
	  
	  <cfif IsDefined('arguments.subType')>
		<cfset child = arguments.subType>
		<cfset StructAppend(child,this,'yes')>
		<cfreturn child>
	  </cfif>
	</cffunction>
	
	<cffunction name="getName">
	  <cfreturn this.firstName + ' ' + this.lastName>
	</cffunction>
	
	<cffunction name="setName">
	  <cfargument name="firstName" required="yes" type="string">
	  <cfargument name="lastName" required="yes" type="string">
	  
	  <cfset this.firstName = arguments.firstName>
	  <cfset this.lastName = agruments.lastName> 
	</cffunction>  
</cfcomponent>



5Employee.cfc
<cfcomponent hint="I am an Employee" extends="com.techspedition.CFCs.5Person">
	<cffunction name="new">
	  <cfargument name="firstName" type="string" required="no">
	  <cfargument name="lastName" type="string" required="no">
	  <cfargument name="gender" type="string" required="no">
	  <cfargument name="dateOfBirth" type="string" required="no">
	  <cfargument name="department" type="string" required="yes">
	  <cfargument name="dateOfHire" type="string" required="yes">
	  <cfargument name="subtype" required="no">
	  
	  <cfinvoke 
	  component="com.techspedition.CFCs.5Person" 
	  method="new" 
	  subtype="#this#" 
	  returnvariable="aPerson" 
	  firstName="#arguments.firstName#" 
	  lastName="#arguments.lastName#" 
	  gender="#arguments.gender#" 
	  dateOfBirth="#arguments.dateOfBirth#">
	  
	  <cfset this = aPerson>
	  <cfset this.employeeID = CreateUUID()>
	  <cfset this.dateOfHire = arguments.dateOfHire>
	  <cfset this.department = arguments.department>
	  
	  <cfif IsDefined('arguments.subType')>
		<cfset child = arguments.subType>
		<cfset StructAppend(child,this,'yes')>
		<cfreturn child>
	  </cfif>
	</cffunction>	  
</cfcomponent>


5testEmployee.cfm
<cfset maxie = CreateObject('component', '5Employee')>
<cfset maxie.new('Maxie', 'Mumm', 'Female', '5/31/1958', 'Accounting', '12/25/1999')>
<cfdump var="#maxie#">


Here is the output:
DEPARTMENT Accounting
YEARBORN null
FIRSTNAME Maxie
LASTNAME Mumm
EMPLOYEEID 6A8A1E0E-C6C9-9A59-B1D1970F03202050
DATEOFHIRE 12/25/1999

gender and dateOfBirth disappear into oblivion. Those to variables are only defined in 5Employee.cfc and they are lost in the dump....well his output in the book shows that they make it along with everything else...well I had a hunch and I changed the code in 5Employee.cfc:

...
<cfinvoke 
	  component="com.techspedition.CFCs.5Person" 
	  method="new" 
	  subtype="#this#" 
	  returnvariable="aPerson" 
	  firstName="#arguments.firstName#" 
	  lastName="#arguments.lastName#">
	  
	  <cfset this = aPerson>
	  <cfset this.employeeID = CreateUUID()>
	  <cfset this.gender = arguments.gender>
	  <cfset this.dateOfBirth = arguments.dateOfBirth>
	  <cfset this.dateOfHire = arguments.dateOfHire>
	  <cfset this.department = arguments.department>


...
this worked. OK WHY is my question, my way makes more sense because essentially we are invoking the 'super class' 5Person.cfc and those variables are not included in 5Person, they are in 5Employee...but in the book, the way he did it, he included gender and dateOfBirth in the invoke statement and it worked...why?
Was This Post Helpful? 0
  • +
  • -

#5 Cutterbl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-August 07

Re: ColdFusion and OOP

Posted 29 August 2007 - 11:05 AM

You wouldn't invoke a person object, within your employee object, unless that 'person' was to be a relation/spouse/boss/whatever property of the object. Since your employee object extends person it should inherit all of the methods and attributes of the person object.

Here is an article (slightly older, 6.1 docs), from the Adobe LiveDocs, that gives a brief explanation on CFC Object Inheritance and the Super Keyword.

Yes, CF has changed a lot since 2002, with many changes from 6.1 to 7, and more from 7 to 8, but most of the 'core' implementation is the same. As far as using OO practices within CF development are concerned, it really depends on how well you understand OO and design patterns. CFOOP tries to give CF noobs a start into OO, and many of the cf frameworks have done a fantastic job of assisting CF developers in transitioning to OO.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1