cfc property annotations for setters/getters

42 views
Skip to first unread message

Jesse Shaffer

unread,
Aug 15, 2014, 4:36:14 PM8/15/14
to ra...@googlegroups.com
Just throwing this out there for discussion... In ACF, you can set annotations on CFC properties to enable/disable the implicit setters and getters. 

I do have several cases where I want "read-only" properties where the value can be retrieved, but not changed by outside influences.  I can achieve this currently, as I mention below, so this is more about adding some syntactic sugar.

ACF Example:
Example.cfc:
------------

component accessors
=true {
   
/**
     * Read only property
     * @setter false
     **/

    property name
="ReadOnly" type="boolean" default=true;

   
/**
     * Write only property (cant think of a good use-case for a write-only property, but its still an option...)
     * @getter false
     **/

    property name
="WriteOnly" type="any";
}


In Railo, you can accomplish the same thing by overriding the implicit public getter/setter with an explicit private method:
component accessors=true {
   
/**
     * Read only property
     **/

    property name
="ReadOnly" type="boolean" default=true;

   
/**
     * Write only property
     **/

    property name
="WriteOnly" type="any";

   
private function setReadOnly() {}
    private function getWriteOnly() {}
}

I personally like the simplicity of using the annotations, but is it something worthy of raising a feature request for?

Chris Blackwell

unread,
Aug 15, 2014, 8:22:04 PM8/15/14
to railo

You can use the getter/setter attributes of cfproperty to do the same thing. e.g.

property name='username' getter='true' setter='false';

Chris

--
Did you find this reply useful? Help the Railo community and add it to the Railo Server wiki at https://github.com/getrailo/railo/wiki
---
You received this message because you are subscribed to the Google Groups "Railo" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/railo/68148936-907d-49fb-b78a-2b96c22e5b22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Shaffer

unread,
Aug 18, 2014, 9:53:04 AM8/18/14
to ra...@googlegroups.com
I don't know how I missed that...  I'm just so used to doing annotations in script now that I forget about attributes.
Reply all
Reply to author
Forward
0 new messages