Andy,

It can be a little confusing at first how to get CFC's to play together if
you haven't much experience programming using an object oriented approach.
>From a procedural perspective, the question can arise "What's the sense of
encapsulation if it prevents objects from working together???!!"

The "trick" is in learning how composition works when you work with CFC's.
Basically speaking, composition (and inheritance) group CFC's together
within the same encapsulation boundary so they CAN work together. Once you
get the hang of it, you've got a whole bunch of options and variations to
choose from, but the basic theme remains the same, if 2 CFC's need to work
together, figure out the best way to form a "working group" so they can.
This is what OO patterns are about, more or less.

For instance, in your example, myCFC2 could be instantiated or passed into
myCFC1. Or ... you could create another CFC, myManagerCFC, and instatiate or
pass into Manager both my1 and my2. Then all your calls from within your app
would be to Manager, and within Manager, your functions would call my1 and
my2 to get things done. In this way, Manager would be acting as a facade.

There are many other variations once you get into this, but the big shift in
moving from procedural programming into object oriented programming (and
that's what you're doing if your going to do it "with out going to the
application scope" ) is learning how to work with encapsulation so it helps
you, rather than gets in your way.



-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Andy Jarrett
Sent: Wednesday, June 01, 2005 2:55 PM
To: [email protected]
Subject: [CFCDev] Accessing another CFC's methods


Hi there,

I have several CFC's in my app which i init into the application scope.

e.g. application.mycfc1 and application.mycfc2

If i want a method from mycfc1 from mycfc2 then i use the following code

<cfset usersName = application.myCFC2.getUsersName(id) />

I just wanted to check this is a good way of doing this? or is there
another i.e. with out going to the application scope?

Cheers

Andy J


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to
[email protected] with the words 'unsubscribe cfcdev' as the subject of the
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]






----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to