|
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.
Good:
objectA.method(session.objectA.aProperty);
OK:
objectA.method(session.objectA);
bad:
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.
barneyb
---
|
