If you want to add/change data or behavior at runtime, you really have two
options. One is to use what you're describing, which is really based on Duck
Typing. CF is a dynamic language and as a result you can add methods to
objects at runtime. However, you're right, this does make the API more
difficult to understand because the object has no definite API, and you are
relying to client code to "know" that a given object has certain properties
or methods if you are adding or removing them dynamically at runtime.

The other option is to use Composition. This is how most strongly-typed
languages change behavior at runtime. The API to the object remains fixed,
but you are free to swap out different objects in the composition
relationship to provide different behavior. An example might be encryption:
say you have an object that needs to perform encryption on a string, but you
want to be able to vary the actual encryption implementation. You can
compose different encryption objects into the target object, and the object
just calls encrypt() on the composed object. Depending on what encryption
object you have composed into the object, the actual encryption
implementation will change.

Hopefully that makes sense.

Brian


On Nov 12, 2007 8:55 AM, Jeff Chastain <[EMAIL PROTECTED]> wrote:

> I have a business case where I need to take a basic business object and
> add
> new properties to it at run time via a series of admin user interfaces.
>  The
> only way I have come up with to do this is to have the business object
> maintain a collection of "properties" that would then have a get / set
> method based upon the property name - like user.getProperty('firstName').
> Something does not seem quite right about this as the business object
> would
> not know what properties it did or did not have, would not be able to
> perform any checks based upon those properties, and it would be up to the
> calling code to know to request the right property.
>
>
>
> I have gone through my book of design patterns, but nothing seems to fit
> here.  Does anybody know of a different / better way to approach this?
>
>
>
> Thanks
>
> -- Jeff
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Check out the new features and enhancements in the
latest product release - download the "What's New PDF" now
http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293132
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to