You might want to post this on the list at cfczone.org. (This is a bit over my head, but I can, at least, point you to a list dedicated to CFCs.)
-----Original Message----- From: Taco Fleur [mailto:[EMAIL PROTECTED] Sent: Monday, January 03, 2005 4:53 AM To: CF-Talk Subject: Typesafe enum design pattern (another go) Just trying to implement the Typesafe Enum Design Pattern in ColdFusion, and am looking for some feedback/input on the following code. I have tried to get some feedback before on the Singleton design pattern, but got not one response, so I am thinking; 1. This is not the list to post to for feedback, only problems. 2. There is no interest in these type of posts. 3. I was so way off that it wasn't even worth replying. 4. Fill in...... So here is another go at another design pattern.. Following is the code to call the CFC ************** <cfscript> DataType = createObject( "component", "_resource.class.database.microsoftSQLServer.DataType" ).init(); </cfscript> <cfoutput> <cfdump var="#DataType.INTEGER.getLower()#"> <cfdump var="#DataType.BIGINT.getUpper()#"> <cfscript> for ( Constant in DataType.instance ) { writeOutput( DataType.instance[ Constant ].getLower() & "<br/>" ); } </cfscript> <cfdump var="#DataType#"> </cfoutput> ************** Following is the CFC itself ************** <cfcomponent displayname="DataType" hint="This CFC implements the Typesafe Enum Design Pattern" output="false" author="Taco Fleur ([EMAIL PROTECTED])"> <!--- This CFC would be a good candidate for the singleton pattern on the other hand it won't be called that much, so it might be a waste in the server scope ---> <!--- Define: Is A Define: Has A ---> <!--- Declare properties for this Object ---> <cfproperty name="upper" access="private" type="any" displayname="Upper" hint="Holds the upper value of the constant." required="true" /> <cfscript> this.instance = structNew(); </cfscript> <cffunction name="init" access="public" returntype="DataType"> <cfscript> // Public static newConstant( name = "BIGINT", lower = -9223372036854775808, upper = 9223372036854775807, type = "numeric" ); newConstant( name = "INTEGER", lower = -2147483648, upper = 2147483647, type = "numeric" ); newConstant( name = "SMALLINT", lower = -32768, upper = 32767, type = "numeric" ); newConstant( name = "TINYINT", lower = 0, upper = 255, type = "numeric" ); newConstant( name = "BIT", lower = 0, upper = 1, type = "numeric" ); newConstant( name = "DECIMAL", lower = "-10^38+1", upper = "10^38-1", type = "numeric" ); // Same as Decimal constant structInsert( this, "NUMERIC", this.DECIMAL, false ); newConstant( name = "MONEY", lower = -922337203685477.5808, upper = 922337203685477.5807, type = "numeric" ); newConstant( name = "SMALLMONEY", lower = -214748.3648, upper = 214748.3647, type = "numeric" ); newConstant( name = "FLOAT", lower = -1.79E+308, upper = 1.79E+308, type = "numeric" ); newConstant( name = "REAL", lower = -3.40E+38, upper = 3.40E+38, type = "numeric" ); newConstant( name = "DATETIME", lower = createDate( 1753, 1, 1 ), upper = createDate( 9999, 12, 31 ), type = "date" ); newConstant( name = "SMALLDATETIME", lower = createDate( 1900, 1, 1 ), upper = createDate( 2079, 6, 6 ), type = "date" ); newConstant( name = "CHAR", lower = 0, upper = 8000, type = "string" ); newConstant( name = "TEXT", lower = 0, upper = 8000, type = "string" ); newConstant( name = "VARCHAR", lower = 0, upper = 2147483647, type = "string" ); newConstant( name = "NCHAR", lower = 0, upper = 4000, type = "string" ); newConstant( name = "NVARCHAR", lower = 0, upper = 4000, type = "string" ); newConstant( name = "BINARY", lower = 0, upper = 8000, type = "string" ); newConstant( name = "VARBINARY", lower = 0, upper = 8000, type = "string" ); newConstant( name = "IMAGE", lower = 0, upper = 2147483647, type = "string" ); // Return the instance of the Object return this; </cfscript> </cffunction> <cffunction name="newConstant" access="package" returntype="DataType"> <cfargument name="name" type="string" required="yes" hint="The name of the constant." /> <cfargument name="upper" type="any" required="yes" hint="The upper value of the constant." /> <cfargument name="lower" type="any" required="yes" hint="The lower value of the constant." /> <cfargument name="type" type="string" required="yes" hint="The type of the constant." /> <cfscript> structInsert( this, arguments.name, createObject( "component", "DataType" ).setConstant( lower = arguments.lower, upper = arguments.upper, type = arguments.type ), false ); // Create a reference in the this.instance structure structInsert( this.instance, arguments.name, this[ arguments.name ], false ); return this; </cfscript> </cffunction> <cffunction name="setConstant" access="package" returntype="DataType"> <cfargument name="upper" type="any" required="yes" hint="The upper value of the constant." /> <cfargument name="lower" type="any" required="yes" hint="The lower value of the constant." /> <cfargument name="type" type="string" required="yes" hint="The type of the constant." /> <cfscript> setUpper( upper = arguments.upper ); setLower( lower = arguments.lower ); setType( type = arguments.type ); return this; </cfscript> </cffunction> <cffunction name="setUpper" access="public" returntype="void"> <cfargument name="upper" type="any" required="yes" hint="The upper value of the constant." /> <cfscript> variables.upper = arguments.upper; </cfscript> </cffunction> <cffunction name="getUpper" access="public" returntype="any"> <cfscript> return variables.upper; </cfscript> </cffunction> <cffunction name="setLower" access="public" returntype="void"> <cfargument name="lower" type="any" required="yes" hint="The lower value of the constant." /> <cfscript> variables.lower = arguments.lower; </cfscript> </cffunction> <cffunction name="getLower" access="public" returntype="any"> <cfscript> return variables.lower; </cfscript> </cffunction> <cffunction name="setType" access="public" returntype="void"> <cfargument name="type" type="string" required="yes" hint="The type of the constant." /> <cfscript> variables.type = arguments.type; </cfscript> </cffunction> <cffunction name="getType" access="public" returntype="numeric"> <cfscript> return variables.type; </cfscript> </cffunction> </cfcomponent> Taco Fleur ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Special thanks to the CF Community Suite Silver Sponsor - New Atlanta http://www.newatlanta.com Message: http://www.houseoffusion.com/lists.cfm/link=i:4:189148 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

