Some answers inline ... hope they help, otherwise keep asking ... Nando

On 3/6/07, Joe Lakey <[EMAIL PROTECTED]> wrote:

I've been using CF for seven years, but I'm new to CFCs and OO
development. Until a few months ago, I only used CFCs as a way to
organize UDFs. I have several questions, and I've included outlines of
the CFCs I'm using in my current project (the code itself is thousands
of lines). If the questions need to be split into different threads, let
me know. Also, if there's a good CFC/OO tutorial or reference out there,
please let me know. I've read the CF documentation and Livedocs. I've
started reading some of the MVC stuff on the web, but it's still a
little above my head. I'm really having trouble differentiating between
the model and controller layers. That said, here are my questions:

1. I use CFC instances in persistent scopes--mostly session--and create
a unique named lock inside each instance.


Is there a specific reason you are using a lock? Ordinarily, this isn't
needed ... but i don't understand your use-case.

I lock any code in the CFC
that sets its properties using the named lock. My question is: do I
still need to lock the scope when I call an instance method from a page?
(I'm moving towards making CFC properties only accessible through its
methods, but some of my earlier work uses the This scope.) What if the
method reads or writes to a database or to another variable in the scope
but outside the CFC?

2. If a CFC extends another CFC, does the init() method need to call
Super.init()?


No, not at all.

If so, why doesn't this create two instances--one of the
"parent" CFC and one of the child CFC?


It can be a  little confusing at first. The parent or super class should
have some common methods that a several child or sub classes need. Then when
you instantiate the sub class, the methods of the super class are present in
the sub class. They kinda merge and become one object when instantiated.

Does super.init() automatically
receive arguments passed to init(),


No

or do they have to be explicitly
passed to super.init()?


Yes


3. If a method overrides a method of a base CFC, does the child method
need to to call super.myMethod()?


No,  if the methods are the same name, then the child method is what is
called. If you want to call the parent method instead, then you'd use the
super. keyword.

What if the child method is only
intended to override part of the parent method's functionality?


If this is the case, you'd probably need to refactor your CFC.

For
instance, the method may set a number of properties, but the child
method only needs to override some of those properties.


Use separate methods to set  each property ...

Also, similar to
question 2, does super.myMethod() receive arguments passed to
myMethod(),


No

or must they be explicitly passed to super.myMethod()?


Yes

4. How is a method of one object made available to the methods of
another object?


There are several ways, but what everyone talks about is "passing an object
into another", composition.

In reality, all that is passed is a reference to the object. CFAS creates a
variable when you instantiate an object in memory, and when you give it some
name in some scope, then it has a reference to that variable. CFCs are
passed by reference.

So what you effectively do is instantiate object1, instantiate object2, and
then within object2 in some method you have an argument that accepts object1
... from there you can use object1 inside that method in object2.

If you then do

cfset variables.object1 = arguments.object1

you can use object1 anywhere within object2

Is that clear enough?




Can a property of the second object be a reference to
the first object? If so, is the first object actually passed by
reference or by value (by duplication?)?
For example, in this code, can firstCfcMethod() call
Variables.SecondCfcReference.secondCfcMethod()?

<cfcomponent displayname="FirstCfc">

  <cfproperty name="SecondCfcReference" type="SecondCfc">

  <cffunction name="init">

    <cfargument name="SecondCfcInstance" type="SecondCfc"
required="yes">

        <cfset Variables.SecondCfcReference=Arguments.SecondCfcInstance>

  </cffunction>

  <cffunction name="firstCfcMethod">

    <cfset Variables.SecondCfcReference.secondCfcMethod() >

  </cffunction>

</cfcomponent>

<cfcomponent displayname="SecondCfc">

  <cffunction name="secondCfcMethod">

    <!--- FUNCTION CODE --->

  </cffunction>

</cfcomponent>

5. If a CFC (FirstCfc) property is a reference to another object
(SecondCfcInstance), can SecondCfcInstance "see" the FirstCfc's
properties and methods?



Don't quite get this question ...

Below are outlines of the CFCs in the app I'm currently working on. If
there are glaring (or minor) errors, I would be very grateful to have
them pointed out and perhaps explained.

Thank you in advance for any help you can offer.

Joe


AdminEmpCFC                   USED FOR EMPLOYEE ADMIN
========================================================================
=======
Variables.LOCK_NAME           UNIQUE NAME (UUID) FOR NAMED LOCK
Variables.DSN                 APPLICATION DSN
Variables.SCOPE               SCOPE IN WHICH INSTANCE EXISTS
Variables.USER_ID             UNIQUE ID OF CURRENT USER

                              NOTE: "SPAN" REFERS TO USER'S SPAN OF
CONTROL
Variables.span_top_mgr_list   LIST - TOP-LEVEL MGRS AND DIRECTORS IN
SPAN
Variables.span_all_mgr_list   LIST - ALL MGRS AND DIRECTORS IN SPAN
Variables.span_all_mgr_data   QUERY - DATA ON ALL MGRS AND DIRECTORS IN
SPAN

Variables.span_emp_data       QUERY - DATA ON ALL EMPS IN SPAN
Variables.span_emp_data_html  HTML CODE FOR EMPLOYEE ADMIN PAGE

Variables.span_all_mgr_js     JAVASCRIPT CODE FOR MGR AND DIRECTOR JS
ARRAYS
                                   FOR DYNAMIC HTML SELECTS

Variables.active_dirs         QUERY - DATA ON ACTIVE DIRECTORS
Variables.active_mgrs         QUERY - DATA ON ACTIVE MANAGERS
Variables.active_emps         QUERY - DATA ON ACTIVE EMPLOYEES
------------------------------------------------------------------------
-------
init()
resetData()                   CLEARS INSTANCE PROPERTIES

getSpanTopMgrAndDirList()     GETS VARIABLES.SPAN_TOP_MGR_LIST; IF IT IS

                                   NOT SET, SETS IT USING DB QUERY
getSpanMgrAndDirList()        GETS VARIABLES.SPAN_ALL_MGR_LIST; IF IT IS

                                   NOT SET, SETS IT USING DB QUERY

getSpanMgrAndDirData()        GETS VARIABLES.SPAN_ALL_MGR_DATA; IF IT IS

                                   NOT SET, SETS IT USING DB QUERY

getMgrAndDirJSArrays()        GETS VARIABLES.SPAN_ALL_MGR_JS
setMgrAndDirJSArrays()        SETS VARIABLES.SPAN_ALL_MGR_JS USING
                                   VARIABLES.SPAN_ALL_MGR_DATA

getUserData()       GETS ALL EMPLOYEE DATA VIEWABLE BY THIS USER FROM
DATABASE
getUserDataHtml()   GETS VARIABLES.SPAN_EMP_DATA_HTML
setUserDataHtml()   SETS VARIABLES.SPAN_EMP_DATA_HTML

getAllDirs()        GETS DATA FOR ALL DIRECTORS FROM DATABASE
getAllMgrs()        GETS DATA FOR ALL MANAGERS FROM DATABASE
getAllEmps()        GETS DATA FOR ALL EMPLOYEES (NON-MGMT) FROM DATABASE
getActiveDirs()     GETS DATA FOR ACTIVE DIRECTORS FROM getAllDirs();
                         SETS VARIABLES.ACTIVE_DIRS
getActiveMgrs()     GETS DATA FOR ACTIVE MANAGERS FROM getAllMgrs();
                         SETS VARIABLES.ACTIVE_MGRS
getActiveEmps()     GETS DATA FOR ACTIVE EMPLOYEES FROM getAllEmps();
                         SETS VARIABLES.ACTIVE_EMPS

addUser()           ADD A NEW USER TO DATABASE
editUser()          EDIT AN EXISTING USER DB RECORD
deleteUser()        DELETE AN EXISTING USER

isUserInSpan()      RETURNS TRUE IF ARGUMENT EMP_ID IS IN
                         VARIABLES.SPAN_EMP_DATA (TODO: RENAME TO
isEmpInSpan)

getOneUserInfo()    GETS ALL DATA FOR ONE EMPLOYEE FROM
VARIABLES.SPAN_EMP_DATA
                         (TODO: RENAME TO getOneEmpInfo)
getUserField()      GETS ONE FIELD FOR ONE EMPLOYEE FROM
                         VARIABLES.SPAN_EMP_DATA (TODO: RENAME TO
getEmpField)
------------------------------------------------------------------------
-------


ReportCFC
========================================================================
=======
Variables.LOCK_NAME      UNIQUE NAME FOR NAMED LOCK
Variables.DSN            APPLICATION DSN
Variables.SCOPE          SCOPE IN WHICH INSTANCE EXISTS
Variables.USER_ID        UNIQUE ID OF CURRENT USER
Variables.USER_POSITION
Variables.USER_OBJECT    REFERENCE TO SESSION.USER (CTCSurveyUserCFC
INSTANCE)

Variables.user_viewable_results    QUERY - RESULTS USER IS ALLOWED TO
ACCESS
Variables.survey_questions         QUERY - ALL SURVEY QUESTIONS
Variables.results_fields           LIST - ALL SURVEY FIELDS FROM RESULTS
TABLE
Variables.recordset                QUERY - CURRENT ACTIVE RECORDSET

Variables.filter         REPORT PARAMETER (ShowAll | FyAndQtr |
DateRange)
Variables.fy             REPORT PARAMETERS
Variables.qtr
Variables.start_date
Variables.end_date
------------------------------------------------------------------------
-------
init()
refreshData()                 CLEARS INSTANCE PROPERTIES

getUserViewableResults()      GET VARIABLES.USER_VIEWABLE_RESULTS
setUserViewableResults()      SET VARIABLES.USER_VIEWABLE_RESULTS
                                   USING readUserViewableResults()
readUserViewableResults()     FETCH DATA FOR
VARIABLES.USER_VIEWABLE_RESULTS
                                   FROM DATABASE

getResultsFields()
setResultsFields()
readResultsFields()

setReportParams()        SETTER/GETTER FOR REPORT PARAMETERS
getReportParams()

getSurveyQuestions()     SETTER/GETTER FOR SURVEY QUESTIONS
setSurveyQuestions()
readSurveyQuestions()    FETCH DATA FOR SURVEY QUESTIONS FROM DATABASE

getReportDataMyCTCs()    THESE GET DATA FOR SPECIFIC REPORTS
getReportDataMyCTCMgrs()
getReportDataCTCDetail()
getReportDataCTCMgrSummary()
getReportDataMyAEs()
getReportDataMyAEMgrs()
getReportDataAEDetail()
getReportDataSalesMgrSummary()
------------------------------------------------------------------------
-------


CTCSurveyUserCFC         EXTENDS FDX_CFCs.FDX_User
========================================================================
=======
Variables.DSN
Variables.SCOPE
Variables.LOCK_NAME

Variables.emp_id         PROPERTIES FOR CURRENT USER FROM LDAP
Variables.first_name
Variables.last_name
Variables.nick_name
Variables.full_name
Variables.phone
Variables.email
Variables.title
Variables.mgr_id
Variables.dept
Variables.dept_num
Variables.address_1
Variables.address_2
Variables.state
Variables.zip
Variables.city
Variables.country
Variables.comat
Variables.mgmt_level

Variables.position       PROPERTY UNIQUE TO CTC SURVEY APP
Variables.dir_id         PROPERTY UNIQUE TO CTC SURVEY APP
Variables.active         PROPERTY UNIQUE TO CTC SURVEY APP

Variables.shadow_id
Variables.logged_in
Variables.app_roles
Variables.page_roles

Variables.direct_reports_user_tbl  LIST - IDS OF USER'S CURRENT DIRECT
REPORTS
Variables.direct_reports_rslt_tbl  LIST - IDS OF USER'S DIRECT REPORTS
AT TIME
                                        OF SURVEY
Variables.direct_reports_all       LIST - IDS OF ALL USER'S DIRECT
REPORTS
                                        (CURRENT AND AT TIME OF SURVEY)
Variables.subordinates_user_tbl    LIST - IDS OF USER'S CURRENT
SUBORDINATES,
                                        INCLUDING DIRECT REPORTS
Variables.subordinates_rslt_tbl    LIST - IDS OF USER'S SUBORDINATES,
INCLUDING
                                        DIRECT REPORTS, AT TIME OF
SURVEY
Variables.subordinates_all         LIST - IDS OF ALL USER'S
SUBORDINATES,
                                        INCLUDING DIRECT REPORTS
(CURRENT AND
                                        AT TIME OF SURVEY)
------------------------------------------------------------------------
-------
init()
logout()

setUserInfo()
getUserInfo()
fetchUserInfo()

getDirectReportsUserTbl()     SETTERS/GETTERS FOR
VARIABLES.DIRECT_REPORTS_xxx
setDirectReportsUserTbl()          IF PROPERTY IS NOT SET, GETTER
INVOKES
getDirectReportsResultsTbl()       SETTER, WHICH READS FROM DATABASE
setDirectReportsResultsTbl()
getDirectReportsAll()
setDirectReportsAll()

getSubordinatesUserTbl()      SETTERS/GETTERS FOR
VARIABLES.SUBORDINATES_xxx;
setSubordinatesUserTbl()           SUBORDINATES ARE ALL EMPLOYEES IN
SPAN OF
getSubordinatesResultsTbl()        CONTROL, INCLUDING DIRECT REPORTS
setSubordinatesResultsTbl()
getSubordinatesAll()
setSubordinatesAll()

mergeEmpIdLists()
------------------------------------------------------------------------
-------


FDX_CFCs.FDX_User
========================================================================
=======
Variables.DSN
Variables.SCOPE
Variables.LOCK_NAME

Variables.emp_id              PROPERTIES FOR CURRENT USER FROM LDAP
Variables.first_name
Variables.last_name
Variables.nick_name
Variables.full_name
Variables.phone
Variables.email
Variables.title
Variables.mgr_id
Variables.dept
Variables.dept_num
Variables.address1
Variables.address2
Variables.state
Variables.zip
Variables.city
Variables.country
Variables.comat
Variables.mgmt_level

Variables.shadow_id
Variables.logged_in
Variables.app_roles
Variables.page_roles
------------------------------------------------------------------------
-------
init()

login()        SETS VARIABLES.LOGGED_IN TO TRUE
loginAs()      SETS Variables.shadow_id; ALLOWS ADMIN TO LOGIN AS
ANOTHER USER
logout()       SETS VARIABLES.LOGGED_IN TO FALSE; CLEARS PROPERTY VALUES

setUserInfo()  SETS PROPERTIES FOR CURRENT USER USING STRUCT FROM
getUserInfo
getUserInfo()  RETURNS USER INFO FROM LDAP IN STRUCT

getShadowId()

isLoggedIn()
isInRole()

setAppRoles()
addAppRole()
removeAppRole()
getAppRoles()
setPageRoles()
addPageRole()
removePageRole()
getPageRoles()
getAllRoles()
------------------------------------------------------------------------
-------


You are subscribed to cfcdev. To unsubscribe, please follow the
instructions at http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

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




You are subscribed to cfcdev. To unsubscribe, please follow the instructions at 
http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

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

Reply via email to