代码之家  ›  专栏  ›  技术社区  ›  tamberg

ColdFusion CFC最佳/推荐做法收集?

  •  9
  • tamberg  · 技术社区  · 6 年前

    有很多文章在那里,但我认为它可能是整洁的,把任何技巧和技巧放在一个地方,通过经验教训。

    我会在这里添加一些链接,让它继续,但我认为最好的是不要长文章,可以谷歌搜索。

    CFC Best Practices

    Macromedia CFC Best Practices

    4 回复  |  直到 15 年前
        2
  •  1
  •   Fabian Steeg    7 年前

    四件事:

    1. 上车 CFCDev mailing list (或者像现在这样的谷歌集团)。

    2. PDF of a Design Patterns 在CFML中,Sean Corfield的演示是一个很好的快速阅读。

    3. http://www.cfdesignpatterns.com 有一些好东西链接到高质量的CFC设计文章。

    4. 关于 design patterns

        3
  •  0
  •   Aaron Greenlee    15 年前

    在使用 ColdBox Framework 当时我没有看到任何关于使用Momentos捕捉属性的帖子;但是,现在我所有的bean都有一个getMomento()和setMomento()方法。对于任何需要将信息从bean传递到DAO其他对象的人,我鼓励这样做。

    在我的测试中,得到一个momento比传递bean和获得属性要快得多。下面是一个例子:

    <cfcomponent name="userBean" output="true" hint="The account bean holds getter/setter information for a user's account.">
    
    <cfproperty name="idUser"           required="true"     type="string"   rules="noZeroLengthString,validEmail"       invalidMessage="failed_data_validation_email"               hint="Key matching the 'accounts' table.">
    <cfproperty name="loginEmail"       required="true"     type="string"   rules="noZeroLengthString,validEmail"       invalidMessage="failed_data_validation_email"               hint="E-mail address.">
    <cfproperty name="password"         required="true"     type="string"   rules="noZeroLengthString,validPassword"    invalidMessage="failed_data_validation_password"            hint="Password stored in a SHA-512 hash.">
    
    <cffunction name="init" output="false" returntype="userBean" hint="Initalizes the userBean with default values.">
        <cfset variables.instance               = structNew()>
        <cfset variables.instance.IDUser        = 0>
        <cfset variables.instance.loginEmail    = "">
        <cfset variables.instance.password      = "">
        <cfreturn this>
    </cffunction>
    
    <!--- SET LOGIN --->
    <cffunction name="setLoginEmail" access="public" returntype="void" output="false">
        <cfargument name="email" type="string" required="true" />
        <cfset variables.instance.loginEmail = trim(arguments.email) />
    </cffunction>
    <cffunction name="getLoginEmail" access="public" returntype="string" output="false">
        <cfreturn variables.instance.loginEmail />
    </cffunction>
    
    <!--- ID --->
    <cffunction name="setIDUser" access="public" returntype="void" output="false">
        <cfargument name="id" type="numeric" required="true" />
        <cfset variables.instance.IDUser = arguments.id />
    </cffunction>
    <cffunction name="getIDUser" access="public" returntype="numeric" output="false">
        <cfreturn variables.instance.IDUser />
    </cffunction>
    
    <!--- PASSWORD --->
    <cffunction name="setPassword" access="public" returntype="void" output="false">
        <cfargument name="password" type="string" required="true" />
        <cfset var pw = arguments.password>
        <cfif len(pw) EQ 0>
            <cfset variables.instance.password = "">
        <cfelse>
            <!---><cfset variables.instance.password = hash(arguments.password, "SHA-512") />--->
            <cfset variables.instance.password = arguments.password>
        </cfif>
    </cffunction>
    <cffunction name="getPassword" access="public" returntype="string" output="false">
        <cfreturn variables.instance.password />
    </cffunction>
    
    <!--- MOMENTO --->
    <cffunction name="setMomento" access="public" returntype="void" output="false">
        <cfargument name="momento" type="struct" required="true" />
        <cfset variables.instance = arguments.momento>
    </cffunction>
    <cffunction name="getMomento" access="public" returntype="struct" output="false">
        <cfreturn variables.instance />
    </cffunction>
    

    干杯,

    My Site