I have a follow up question relating to using an init() with extended classes?  I have several DAOs that all have the same instance data, basically a schema, and a util lib.  I was thinking about having them extend an abstract DAO, and put the init() and some getters() in the super class.  I am just curious what type the init() would have to return for this to work? 
 
<cffunction name="init" returntype="this">?
 
or
 
<cffunction name="init" returntype="AbstractDAO">?
 
Or would I have to override the init() in the subclasses?
 
Thanks in advance?
 
Justin
-----Original Message-----
From: Jim Davis [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 17, 2004 5:46 AM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] Using INIT - WAS: RFC, CFC Best Practices

I'm not sure if this will help, but I've handled this (poorly) by creating a "DP_Null" variable (my company is "The Depressed Press" thus the "DP").

 

Although I use a root component (extended by all others) to do this you don't need to: in the pseudo constructor area I create this.dpnull = true, then in the init I do this.dpnull = true.

 

I can then test if the component is "dpnull" anyplace to see if it's been inited ( <cfif NOT myCFC.dpnull> ).  Considering it with the benefit of hindsight however "null" really isn't the concept I wanted... it probably should be something like "dpundefined" or the like... maybe I'll change it.

 

The method injection idea of yours sounds pretty slick to me ... and sounds like it should work.  Both concepts together (a way to hide methods not ready to be used and a way to easily check state) seem to be getting closer.

 

Jim Davis

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Temm
Sent: Tuesday, March 16, 2004 1:59 PM
To: [EMAIL PROTECTED]
Subject: [CFCDev] Using INIT - WAS: RFC, CFC Best Practices

 

Michael,

I think in Java, you don't have access to non-static methods until the object is instantiated.  I wonder if one way of making this happen for you would be to hide your non-static methods until init has been called.  What would happen if you declared the methods like:

<cffunction name="instance.myMethod ...>

Would this place the method in this.instance.myMethod?  If so, init() could 'copy' the method into the THIS scope and make it accessible like a normal method:

     this.myMethod= this.instance.myMethod;

 

Haven't tried this myself yet (no time today) but seems like a neat experiment and would minimise the changes to your code.  It would also speed things up because these methods wouldn't have to check to see whether the object was instantiated.

==========================

Chip Temm

Dir Knowledge Architecture

Conservation International

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]On Behalf Of Dawson, Michael
Sent: 16 March 2004 10:57
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] RFC, CFC Best Practices

I was just thinking about that last night...

 

My plan was to add a check in each method, but, like you have said, I don't really want to add all that code.

 

How is this done in a real OOP language?  Do those languages have the constructs to better allow this or do you still have to add code in each method?

 

While we are at it and can get some good suggestions, what would be the appropriate reponse in each method?  Throw an error such as: "Instance not inited"?

 


From: Raymond Camden [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 16, 2004 9:38 AM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] RFC, CFC Best Practices

Speaking of init - how do folks handle cases where they want to force an init w/ arguments? For example, maybe the CFC needs a datasource name in order to work correctly. I don't want to add checks to all my methods to make sure Init() was called. I _could_ use defaults but that wont apply in all cases.

 

=======================================================================
Raymond Camden, ColdFusion Jedi Master for Mindseye, Inc
Member of Team Macromedia

Email    : [EMAIL PROTECTED]
Blog     : www.camdenfamily.com/morpheus/blog
Yahoo IM : morpheus

"My ally is the Force, and a powerful ally it is." - Yoda

 

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dawson, Michael
Sent: Tuesday, March 16, 2004 9:24 AM
To: [EMAIL PROTECTED]
Subject: RE: [CFCDev] RFC, CFC Best Practices

I would rather use a specific Init() method rather than rely on a behavior of the CFC.  I previously used the psuedo-constructor area, but with an uneasy feeling that MACR may change it and, in turn, break my code.

 

By specifying Init(), MACR is less-likely to break my code w/o affecting all other users as well.

 

A compromise would be to coding an Init() method, but also invoking that method in the psuedo-constructor area...

Reply via email to