>Hi,
>
>I'm a fairly new to CFCs (which seems cool). I have a little issue:
>
>I have two CFCs, let's call them CFCmain and CFCdao. CFCmain extends
>CFCdao, the former supplies the main interfaces, while the latter
>provides the data access (SQL) functions.
>
>I designed these to be unaware of any shared scopes. I set the dsn to
>use using a property on CFCmain (it sets a default value when first
>instatiated).
>
>But, the property value on CFCmain (THIS.dsn), is not accessible at all
>to CFCdao -- right? And there is no way to have this property on CFCdao,
>and it is then inherited to CFCmain (since you are not allowed to use
>the this scope on a "base" object, right?).
>
>This means, in practice -- that the dsn string needs to be passed to any
>of my CFCdao functions (where the dsn is needed).
>
>Please let me know if my logic is correct, and if there is any
>preferred/alternative way to design this!
>

Well, in my mind, you're not using inheritance correctly. The "rule" I
strictly go by for using inheritance is that you should be able to use the
two objects in the following sentence:

[child class] is a [parent class]
car is a vehicle

In your case CFCmain is *not* a CFCdao. You should be using the notion of
"composition," which is to say that CFCmain *has* a CFCdao. To use
composition in your case, I'd probably just make a createObject() call
either in the quasi-constructor area or in my init() function (of which all
of my CFCs have) of the CFCmain class and pass in the name of the dsn to the
CFCdao's init() function.

All that being said, you are correct that the parent class does not have
access to THIS.dsn in the child class. The child class has access to the
paren't variables, but not the reverse (that I'm aware of).

Regards,
Dave.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to