What about the constructor function? Shouldn't I set the properties in
the THIS scope when initializing a component?

Also, what is the difference between the variables scope and the
arguments scope withing a method? I have seen properties defined using
the cfargument tag referenced in the method using both the arguments
scope and the variables scope.

-Aaron

On 2/16/06, James Holmes <[EMAIL PROTECTED]> wrote:
> Yes, encapsulation is an important part of OO and yes many people don't care.
>
> If you want to maintain the encapsulation, don't set thigns in the
> THIS scope - use a setter method to set them in the VARIABLES scope
> (and a getter method to get them out again):
>
> <cfscript>
>  newUser = createobject("component", "user");
>  newUser.setname("john");
> </cfscript>
>
> On 2/17/06, Aaron Roberson <[EMAIL PROTECTED]> wrote:
> > Friends,
> >
> > I am learning Java and CFC development in ColdFusion at the same time.
> > I keep going back and forth between the two because they complement
> > each other so well. Anyways, my question is not in regards to the
> > specifics of the language, but with OOP design patterns and
> > encapsulation.
> >
> > HERE IT GOES:
> >
> > In my Java book it says that if a method is public, a data filed could
> > be assigned a value directly, BUT doing so "violates an important
> > principle of object-oriented programming -- that of data hiding using
> > encapsulation.
> >
> > However, I have seen alot of CF developers write code that directly
> > assigns values to data fields in CFC's like the following:
> >
> > CALLING PAGE
> >
> > <cfscript>
> > newUser = createobject("component", "user");
> > newUser.name = "john"
> > newuser.setname();
> > </cfscript>
> >
> > COMPONENT
> >
> > <cfcomponent hint="manages users">
> >
> > <cfscript>
> > init();
> > </cfscript>
> >
> > <cffunction name="init" access="public" output="no" hint="psuedo 
> > constructor">
> > <cfset this.userID = "#createUUID()#">
> > <cfreturn this>
> > </cffunction>
> >
> > <cffunction name="setuser" access="public" output="no" hint="sets user 
> > info">
> > <cfargument name="userID" type="UUID" required="yes">
> > <cfset arguments.userID = this.userID>
> > <!--- processing code --->
> > </cffunction>
> >
> > </cfcomponent>
> >
> >
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:232661
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=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to