Thanks for the
explanation. That does clear things up quite a bit. The rules are
if the CFC is a controller, than it is okay to call on the session scope,
however when dealing with Model CFCs these should be self
contained.
Sean
-----Original
Message-----
From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Barney Boisvert
Sent: Friday, August 08, 2003 4:03
PM
To:
[EMAIL PROTECTED]
Subject:
RE: [CFCDev] App Structure - Data passing between CFC
The first
option is better. Objects shouldn't know anything about other objects,
so objectB shouldn't need to get anything out of session.objectA. You
could also pass a reference to session.objectA as a whole to a method of
objectB. However, if objectA has a lot of data, it's probably better to
only pass the relevant values for clarity's sake.
objectA.method(session.objectA.aProperty);
objectA.method(session.objectA);
objectA.method(); //
where the method body references session.objectA
To put it
another way, any given CFC method should [usually] only interact with
arguments and local variables. Anything else should be considered
inaccessible, even though ColdFusion doesn't actually make it that
way.
I
carefully added the "usually" in that statement, because there are instances
where it makes sense to break encapsulation, and probably situations where you
flat out HAVE to do it. For instance, if you need to make one of the
three calls above from within a CFC controller (as Mach-ii probably does),
that CFC has no choice but to call the session scope directly. However
the called CFC shouldn't have to break encapsulation.
---
Barney Boisvert, Senior Development
Engineer
AudienceCentral
[EMAIL PROTECTED]
voice :
360.756.8080 x12
fax :
360.647.5351
www.audiencecentral.com
-----Original
Message-----
From:
[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of sean
Sent: Friday, August 08, 2003 12:47
PM
To:
[EMAIL PROTECTED]
Subject:
[CFCDev] App Structure - Data passing between CFC
Hi All!
I have been developing CFCs for
a little while, avoiding many of the pitfalls because my use of them have
been limited to building varied and disconnected
functions.
However now that the Mach ii
framework is out, I have a few question as to what is considered best
practice when it comes to passing data from one object to another.
Specifically now that an object (it’s properties and method can exist in a
shared scope)
For example if object b needs a
property of session.objectA.
Should the call be
<cfset
objectb.somefunction(this.aProperty)
or should the call simply be
<cfset objectb.somefunction()
assuming
that the function in objectb will just grab the session scoped property (as
in session.objecta.aProperty)
This may be simple, but I am starting
to think that my call logic is overly complicated as I mixed between the
two.
Your help is
appreciated
Sean
Scott