Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become an Expert!

Join 244,282 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,171 people online right now. Registration is fast and FREE... Join Now!




ColdFusion and OOP

 
Reply to this topicStart new topic

ColdFusion and OOP, questions about CF and OOP

supersssweety
14 Aug, 2007 - 12:52 PM
Post #1

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 339



Thanked: 3 times
Dream Kudos: 125
My Contributions
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

User is offlineProfile CardPM
+Quote Post


skyhawk133
RE: ColdFusion And OOP
14 Aug, 2007 - 12:56 PM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 16,441



Thanked: 117 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
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.
User is online!Profile CardPM
+Quote Post

supersssweety
RE: ColdFusion And OOP
14 Aug, 2007 - 12:58 PM
Post #3

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 339



Thanked: 3 times
Dream Kudos: 125
My Contributions
QUOTE(skyhawk133 @ 14 Aug, 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.

thank ya thank ya
User is offlineProfile CardPM
+Quote Post

supersssweety
RE: ColdFusion And OOP
15 Aug, 2007 - 10:05 AM
Post #4

D.I.C Regular
Group Icon

Joined: 16 Mar, 2007
Posts: 339



Thanked: 3 times
Dream Kudos: 125
My Contributions
QUOTE(skyhawk133 @ 14 Aug, 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.


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:
CODE

<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
CODE

<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
CODE

<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:

...
CODE

<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?
User is offlineProfile CardPM
+Quote Post

Cutterbl
RE: ColdFusion And OOP
29 Aug, 2007 - 10:05 AM
Post #5

New D.I.C Head
*

Joined: 29 Aug, 2007
Posts: 2


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 02:16PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month