|
Hi Folks!
Well I am finished with my object layer in my app. And I am right now working on a thin layer between the object layer and the database.
I have copied below an example of an object and its constructor. I would love any feedback on it! I am concerned about whether my *constructor* is built correctly and is being called correctly by the auction.CFC.
FYI, the thinking behind this approach is that the constructor would be called from within the auction.cfc in configure(). The constructor would then worry about getting the data from a SQL DB and return the query back to the auction object.
Thanks,
Sean Scott
***Auction.cfc****
<cfcomponent hint="Auction Object">
<!--- Set your default properties ---> <cfset variables.auctionID = 0 /> <cfset variables.assetTitle = "" /> <cfset variables.description = "" /> <cfset variables.bidOpenTime = "" /> <cfset variables.bidCloseTime = "" />
<!--- CONFIGURATION ---> <!--- configure the class ---> <cffunction name="configure"> <cfargument name="auctionID" type="numeric" required="yes" />
<!--- call constructor and initialize ---> <cfset constructor = CreateObject( 'Component','Store_Auction' ).configure( arguments.auctionID ) />
<cfset setAuctionID( constructor.getAuctionID( ) ) /> <cfset setAssetTitle( constructor.getAssetTitle( ) ) /> <cfset setDescription( constructor.getDescription( ) ) /> <cfset setBidOpenTime( constructor.getBidOpenTime( ) ) /> <cfset setBidCloseTime( constructor.getBidCloseTime( ) ) /> </cffunction>
<!--- GETTERS AND SETTERS ---> <!--- the nitty greety stuff ---> <cffunction name="setAuctionID"> <cfargument name="auctionID" type=""type="numeric" required="true" /> <cfset variables.auctionID = arguments.auctionId /> </cffunction>
<cffunction name="getAuctionID" returntype="numeric"> <cfreturn variables.auctionID /> </cffunction>
<cffunction name="setAssetTitle"> <cfargument name="assetTitle" type="string" required="true" /> <cfset variables.assetTitle = arguments.assetTitle /> </cffunction>
<cffunction name="getAssetTitle" returntype="string"> <cfreturn variables.assetTitle /> </cffunction>
<cffunction name="setDescription"> <cfargument name="description" type="string" required="true" /> <cfset variables.description = arguments.description /> </cffunction>
<cffunction name="getDescription" returntype="string"> <cfreturn variables.description /> </cffunction>
<cffunction name="setBidOpenTime"> <cfargument name="bidOpenTime" type="date" required="true" /> <cfset variables.bidOpenTime = arguments.bidOpenTime /> </cffunction>
<cffunction name="getBidOpenTime" returntype="date"> <cfreturn bidOpenTime /> </cffunction>
<cffunction name="setBidCloseTime"> <cfargument name="bidCloseTime" type="date" required="true" /> <cfset variables.bidCloseTime = arguments.bidCloseTime /> </cffunction>
<cffunction name="getBidCloseTime" returntype="date"> <cfreturn bidCloseTime /> </cffunction>
</cfcomponent>
*** Auction Object constructor *** <cfcomponent hint="this object will be used to store and if needed retrieve bids from the asset table" extends="machIIAuction.Model.Store">
<cfset variables.auctionID = 0 /> <cfset variables.assetTitle = "" /> <cfset variables.description = "" /> <cfset variables.bidOpenTime = "" /> <cfset variables.bidCloseTime = "" />
<cffunction name="configure"> <cfargument name="auctionID" required="yes" type="numeric" /> <cfset super.configure() />
<cfset construct = open() />
<cfset setAuctionID( construct.auctionID ) /> <cfset setAssetTitle( construct.asset_title ) /> <cfset setdescription( construct.description ) /> <cfset setBidOpenTime( construct.bidOpenTime ) /> <cfset setBidCloseTime( construct.bidCloseTime ) /> </cffunction>
<cffunction name="open" returntype="any"> <cfargument name="auctionID" type="numeric" required="true" />
<cfquery name="getAuction" datasource="#this.getDsn()#"> SELECT * FROM bid WHERE auctionID = arguments.auctionID </cfquery>
<cfreturn getAuction /> </cffunction>
<cffunction name="setAuctionID"> <cfargument name="auctionID" type=""type="numeric" required="true" /> <cfset variables.auctionID = arguments.auctionId /> </cffunction>
<cffunction name="getAuctionID" returntype="numeric"> <cfreturn variables.auctionID /> </cffunction>
<cffunction name="setAssetTitle"> <cfargument name="assetTitle" type="string" required="true" /> <cfset variables.assetTitle = arguments.assetTitle /> </cffunction>
<cffunction name="getAssetTitle" returntype="string"> <cfreturn variables.assetTitle /> </cffunction>
<cffunction name="setDescription"> <cfargument name="description" type="string" required="true" /> <cfset variables.description = arguments.description /> </cffunction>
<cffunction name="getDescription" returntype="string"> <cfreturn variables.description /> </cffunction>
<cffunction name="setBidOpenTime"> <cfargument name="bidOpenTime" type="date" required="true" /> <cfset variables.bidOpenTime = arguments.bidOpenTime /> </cffunction>
<cffunction name="getBidOpenTime" returntype="date"> <cfreturn bidOpenTime /> </cffunction>
<cffunction name="setBidCloseTime"> <cfargument name="bidCloseTime" type="date" required="true" /> <cfset variables.bidCloseTime = arguments.bidCloseTime /> </cffunction>
<cffunction name="getBidCloseTime" returntype="date"> <cfreturn bidCloseTime /> </cffunction>
</cfcomponent> |
- RE: [CFCDev] DB and OO question sean
- RE: [CFCDev] DB and OO question Raymond Camden
- Re: [CFCDev] DB and OO question Sean A Corfield
- RE: [CFCDev] DB and OO question Raymond Camden
- Re: [CFCDev] DB and OO question Sean A Corfield
- RE: [CFCDev] DB and OO question sean
- Re: [CFCDev] DB and OO question Sean A Corfield
- RE: [CFCDev] DB and OO question Justin Balog
- Re: [CFCDev] DB and OO question Sean A Corfield
- RE: [CFCDev] DB and OO question Brad Howerter
