Skip to main content
Inspiring
December 13, 2013
Question

Using 'variables.instance' structure and implicit getters/setters

  • December 13, 2013
  • 1 reply
  • 855 views

I am adopting the use of creating a variables.instance (I use 'variables.my') structure to separate instance data from the object, however I have a question when it comes to ColdFusion creating implicit getters and setters based on that object's defined properties.

BEFORE, if I had a Name property, CF would create getName() and setName() for me, and it would update the variables.Name private variable accordingly in each.  But now that my variables are being stored in 'variables.my.Name', does this mean I can no longer use ColdFusion's implicit getters and setters? (because it would improperly be attempting to execute getName and be looking for variables.Name, when that data now exists in variables.my.Name?

Are there any methodologies around that allow me to utilize CF's implicit getters/setters while using this 'my' instance variable and have them work with one another?

    This topic has been closed for replies.

    1 reply

    Carl Von Stetten
    Legend
    December 13, 2013

    Yes, nesting the component's variables into a custom structure (like variables.instance or variables.my) will break the implicit getter/setter functionality.  You'll have to explicitly create getter and setter methods.

    -Carl V.

    Inspiring
    December 13, 2013

    Thanks for the confirmation Carl.

    How cool, then, would it be if ColdFusion 11 supported something like:

    <cfcomponent

         accessors="true"

         implicitpropertyprefix="my."

         ...

    That way I could specify "my." as the property prefix and when it goes to create those implicit getters and settings, it will concatenate that into 'variables.my.' as the prefix when it alters property values or returns them.

    Carl Von Stetten
    Legend
    December 13, 2013

    Sounds like a great Enhancement Request to put in the bug tracker.

    -Carl V.