My recommendation is to use class style get/set instance functions for data hiding requirements.

Explanation.

Encapsulation means data and functions about an object are defined together as a class. Data hiding is a programming technique that is an indirect access to a class's data. Data hiding is usually implemented by extending class functions with function names like getter and setter.

Two styles of getter and setter functions are often used.
class - the class name as the function and variable name passed with value - setContact("lastname", #form.lastname#) data - variable name with value passed as value. setContactLastName(#form.lastname#)

Either style allows data hiding.

In a CFC all instance functions are public scope whereas data variables can be either public or private scope. Data hiding functions can be used with either scope. Some proponents say data hiding with private variables should only be used. I think this limits the benefits of class structures.

With CFSQLTool, the wizards generate class style get/set functions and public data scope instance variables.

There are 3 reasons for using class functions style.
Less code. Unless the setter is doing data verification, there is no need for separate functions for each instance variable. Namespace management - mullti-level hierarchies allow lower levels to access higher level values. e.g. contact.employee.staff getContact() works in all levels but only instance in contact. Variable scope. - class functions tend to be more scopeless for either public or private variables.

Further.

Do not be afraid to use public variables. You may not need data hiding get/set functions. cfcContact.lastname = form.lastname is an encapsulated structure. cfcContact.setContact("lastname", #form.lastname#) is encapsulation using data hiding.

Joseph

-----------------------------------------------------------------------
http://www.switch-box.org

Switch_box                      MediaFirm, Inc.
www.Switch-box.org              Loveland, CO  USA



----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to