|
I’ve set the Authenticator to receive an instance of UserGateway in the init() method, but have a slight problem with the type attribute.
This code doesn’t work:
<cffunction name="init" returntype="Authenticator" output="false" access="public" hint="Basic constructor"> <cfargument name="userGateway" type="UserGateway" required="yes" hint="Reference to a UserGateway instance"> <cfset variables.userGateway = arguments.userGateway> <cfreturn this/> </cffunction>
It works when I change it to:
<cffunction name="init" returntype="Authenticator" output="false" access="public" hint="Basic constructor"> <cfargument name="userGateway" type="com.myApp.user.UserGateway" required="yes" hint="Reference to a UserGateway instance"> <cfset variables.userGateway = arguments.userGateway> <cfreturn this/> </cffunction>
But now I have application specific dependency again by having to use ‘com.myApp.user.UserGateway’, as ‘myApp’ will change for every new site. Is there any way I can get around this?
Thanks
-----Original Message-----
If you want the Authenticator to be oblivious to which instance of UserGateway it is using - then you have to pass it in (not necessary in the init() method but most likely - and at least before you use it).
Creating a UserGateway internally will then create a dependency on THAT particular class. What you want is only a dependency on the interface (not a specific implementation of the interface).
Regards, Gary On 11/2/05, Gareth Cole <[EMAIL PROTECTED]> wrote: That seems to make sense. Should I pass a reference to an instance of UserGateway in the init() method of Authenticator.cfc ?
-----Original Message----- Subject: Re: [CFCDev] how do you implement different read methods?
It's ok for the Authenticator to call the UserGateway.GetUserById(numeric UserId) method.
The point is that you should be able to replace your UserGateway with a completely different implementation without having to make changes to the Authenticator object.
As long as the interface presented by the UserGateway (and used by the Authenticator) remains the same you can do this.
On 01/11/05, Gareth Cole < [EMAIL PROTECTED]> wrote: Thanks Raphael.
This does mean that my Authenticator.cfc will need to know about the UserGateway.cfc. Is this ok, or should the Authenticator.cfc not need to know about the rest of the application? It seems that the authentication will be tightly coupled to the current application…
-----Original
Message----- Subject: RE: [CFCDev] how do you implement different read methods?
Hi Gareth
Just like you, I'm new to OO and always interested in best practice. In your case, I think I would do what I already saw in other apps. I would make a UserGateway.cfc where I would implement functions like searchUser(), getUserByName() etc. So I would basically have a UserDAO, UserBean and a UserGateway to handle all user functions I can think of.
Regards Raphael
Gerber -----Original Message----- Hi Folks,
I'm new to the list and OO in general, so I'd appreciate some advice.
I've built UserBean.cfc and UserDAO.cfc and both seem to be working. The read method works fine, loading the UserBean.cfc based on the table's primary key (userID).
I'm know building an Authenticator.cfc which has 1 function checkCredentials(). This should take username and password as arguments and return the userID (it will throw an exception if the credentials aren't right).
I'm not sure what is best practice to implement this though. The options I see are:
Although I'm still starting off with this, I imagine there will be quite a few occasions where this sort of thing will occur i.e . reading an object by a non-primary key field.
Is there a best practice way of doing this?
Thanks,
Gareth ---------------------------------------------------------- ---------------------------------------------------------- An archive of the CFCDev list is available at www.mail-archive.com/[email protected] ----------------------------------------------------------
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com). An archive of the CFCDev list is available at www.mail-archive.com/[email protected] |
- RE: [CFCDev] how do you implement different read methods? Gareth Cole
