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:232463
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

Reply via email to