>From my initial OO experience, I would say this is an acceptable
practice.  I have seen/done this very thing in DAOs to return beans to
the caller.

Also, I use this to return error objects from form validator objects.
It works quite well.

If you haven't you should subscribe to the CFC Mailing list at
http://www.cfczone.org/

M!ke 

-----Original Message-----
From: James Holmes [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 16, 2005 5:54 AM
To: CF-Talk
Subject: Object composition and calling objects

I'd like to check on some of the reading I've been doing. 

I am starting to use composition in my CFCs (because I only use
inheritance for an "is-a" relationship). I want to reuse the objects
I've instantiated in the central object from the outside; the reading
I've done suggests the best way to do this is to use a getter method
that returns the instantiated object.

E.g. I have some sort of central component

<cfcomponent output="no" hint="The central component">

  <cffunction name="init" output="false" returntype="void"
access="public"
hint="The method to instantiate a new object">
    <cfset oObject1 = CreateObject("component","Component1")>
    <cfset oObject2 = CreateObject("component","Component2")>
  </cffunction>

  <cffunction name="getObject1">
    <cfreturn _oObject1>
  </cffunction>

  <cffunction name="getObject2">
    <cfreturn _oObject2>
  </cffunction>

   ...etc etc

</cfcomponent>

I could then, in the CF page that uses the central component, do this:

<cfset oMyCentralObject =
CreateObject("component","CentralComponent").init()>
<!--- now call a method1 in object1--->
<cfset MyMethodReturn = oMyCentralObject.getObject1().Method1()

This is how some articles say it should be done - any feedback?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:198932
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to